# Pagination Elastic Search

**URL:** <https://discuss.elastic.co/t/pagination-elastic-search/167071>\
**Category:** Elasticsearch\
**Created:** [February 5, 2019, 7:50am UTC](https://discuss.elastic.co/t/pagination-elastic-search/167071 "2019-02-05T07:50:48Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yash\_Kapoor](https://avatars.discourse-cdn.com/v4/letter/y/5f9b8f/32.png) [@Yash\_Kapoor](https://discuss.elastic.co/u/Yash_Kapoor)\
**Post date:** [February 5, 2019, 7:50am UTC](https://discuss.elastic.co/t/pagination-elastic-search/167071/1 "2019-02-05T07:50:48Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![johnrabi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/johnrabi/32/67223_2.png) [@johnrabi](https://discuss.elastic.co/u/johnrabi)\
**Post date:** [February 5, 2019, 8:08am UTC](https://discuss.elastic.co/t/pagination-elastic-search/167071/2 "2019-02-05T08:08:14Z")

</div>

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  
}

---

<div class="post-metadata">

**Author:** ![Yash\_Kapoor](https://avatars.discourse-cdn.com/v4/letter/y/5f9b8f/32.png) [@Yash\_Kapoor](https://discuss.elastic.co/u/Yash_Kapoor)\
**Post date:** [February 5, 2019, 8:17am UTC](https://discuss.elastic.co/t/pagination-elastic-search/167071/3 "2019-02-05T08:17:45Z")

</div>

Hello @johnrabi

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

Any solution to this problem?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 5, 2019, 8:18am UTC](https://discuss.elastic.co/t/pagination-elastic-search/167071/4 "2019-02-05T08:18:34Z")

</div>

From 1000, size 1000 to get the next 1000.

---

<div class="post-metadata">

**Author:** ![Yash\_Kapoor](https://avatars.discourse-cdn.com/v4/letter/y/5f9b8f/32.png) [@Yash\_Kapoor](https://discuss.elastic.co/u/Yash_Kapoor)\
**Post date:** [February 5, 2019, 8:20am UTC](https://discuss.elastic.co/t/pagination-elastic-search/167071/5 "2019-02-05T08:20:46Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 5, 2019, 8:47am UTC](https://discuss.elastic.co/t/pagination-elastic-search/167071/6 "2019-02-05T08:47:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pranav24](https://avatars.discourse-cdn.com/v4/letter/p/b19c9b/32.png) [@pranav24](https://discuss.elastic.co/u/pranav24)\
**Post date:** [February 6, 2019, 5:51am UTC](https://discuss.elastic.co/t/pagination-elastic-search/167071/7 "2019-02-06T05:51:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Yash\_Kapoor](https://avatars.discourse-cdn.com/v4/letter/y/5f9b8f/32.png) [@Yash\_Kapoor](https://discuss.elastic.co/u/Yash_Kapoor)\
**Post date:** [February 12, 2019, 6:45am UTC](https://discuss.elastic.co/t/pagination-elastic-search/167071/8 "2019-02-12T06:45:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 12, 2019, 6:45am UTC](https://discuss.elastic.co/t/pagination-elastic-search/167071/9 "2019-03-12T06:45:53Z")

</div>

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