Pagination Elastic Search

How do we use pagination in elastic search ?

I have been using the size field with from field with size field set to 1000 and from field to 0.
{ "from : 0, "sort": .... , "_source": ... , "size": 1000 }

Even after this query i am getting more than 1000 hits. How can we solve this?

hi @Yash_Kapoor,
you can use like this , how many total hits in your Es ?
{
"query": {
"bool": {
"must": [
{
"match_all": {}
}
],
"should":
}
},
"from": 0,
"size": 1000
}

Hello @johnrabi

I tried the given query but the hits are still more than 1000. (3621 hits)

Any solution to this problem?

From 1000, size 1000 to get the next 1000.

Hello @dadoonet

I want the first 1000 results only therefore the from field in set to 0.
But still the number of hits are more. How to improve this?

That's not about pagination then.
You want to export all results?

In that case, if the number of hits is reasonable ( < 10000 ), you can set size to 10000.
Otherwise you need to use the scroll API.

Hi @Yash_Kapoor
If you are talking about the value of "total" under hits, It is the count of document matched your search string. But the number of documents retrieved will be 1000 only.

Try testing it with lower size such as 2 or 3. This would retrieve only 2 or 3 but the value of "total" under hits would be the same.

hello Pranav initially i was cionfusing total results with total hits. The query is working fine. Thankyou

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.