0

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

1 Answer 1

2

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" }
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Note: you can only page through a maximum of {index.max_result_window documents} (which defaults to 10,000) documents this way. If you ever expect to then you'll need to use either the "Search After" or "Scroll API"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.