I am listening a traffic and inserting these traffic's data to elasticsearch continually. And I want to search these datas with my python script.
Here is small part of my python code,
test = es.search(
index="argus_data",
body=dict(query=search_body["query"],
size= "1000") # I want to do this "unlimited"
)
pprint(test)
I dont know what is my size because I have new data continually. how to manage this situation please help me to solve this issue,Thanks.
You can do it this way:
test=es.search(index=['test'],doc_type=['test'],size=1000, from_=0)
Then change from_
gradually until you get all of the data.
from_ – Starting offset (default: 0) Elasticsearch-Py API Documentation
First get number of hits by using test['hits']['total'] into a variable, then pass it to size.
You have to use the query two times. The first time you use it to get number of hits(don't pass size argument).
test=es.search(index=['test'],doc_type=['test'])
size=test['hits']['total']
Second time use the query along with size
test=es.search(index=['test'],doc_type=['test'],"size":size)
You will get error if there will be more than 10000 observation..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With