Ari
Ari

Reputation: 6159

How to scroll through elastic query results, python

I'm querying my elastic search server and limiting it to 100 results, but there could be a potential of 5000+ results, but for speed I don't want to overload the users connection trying to send it all in bulk.

data = es.search(index=case_to_view, size=100,body={
   "query": {
       "range" : {
           "someRandomFIeld" : {
               "gte" : 1,
           }
       }
   }
})

This is doing two things, getting me results that have the field type and only getting the results where that field type exists if its value is greater than equal to 1.

data['hits']['total'] # 5089

How do I let the user get the next lot of results from the same query, ie. The next 100, previous 100, etc

Upvotes: 0

Views: 77

Answers (1)

Kevin Mansel
Kevin Mansel

Reputation: 2371

You'll want to utilize the "from" and "size" properties.

You can see it here in the 7.0 documentation.

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-from-size.html

ex :

{
    "from" : 0, "size" : 10,
    "query" : {
        "term" : { "user" : "kimchy" }
    }
}

Upvotes: 2

Related Questions