# Pagination with HighLevelRestClient

**URL:** <https://discuss.elastic.co/t/pagination-with-highlevelrestclient/262146>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [January 25, 2021, 5:05pm UTC](https://discuss.elastic.co/t/pagination-with-highlevelrestclient/262146 "2021-01-25T17:05:25Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![filmac79](https://avatars.discourse-cdn.com/v4/letter/f/a4c791/32.png) [@filmac79](https://discuss.elastic.co/u/filmac79)\
**Post date:** [January 25, 2021, 5:05pm UTC](https://discuss.elastic.co/t/pagination-with-highlevelrestclient/262146/1 "2021-01-25T17:05:26Z")

</div>

Hello,  
I would like to use HighLevelRestClient to fetch all results matching a given query using pagination. Now, checking on the rest api I can found that scroll api have been replaced by search\_after.  
So I checked the HighLevelRestClient documentation in order to understand how to implement pagination but there I found documentation only for the scroll api. So which is the right implementation? I am not performing this query in order to show results to the user but to process a batch of data. Of course while paginating I can still receive data to write or to remove from the index so I would like to keep a coherent view while paginating. Can you please tell me which is the bast way to paginate? Also, I made an experiment with search\_after (using the HighLevelRestClient) and it´s working but I don´t see any PIT (point in time) parameter.  
Thanks a lot!

---

<div class="post-metadata">

**Author:** ![JasonStoltz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jasonstoltz/32/49893_2.png) [@JasonStoltz](https://discuss.elastic.co/u/JasonStoltz)\
**Post date:** [January 25, 2021, 5:15pm UTC](https://discuss.elastic.co/t/pagination-with-highlevelrestclient/262146/2 "2021-01-25T17:15:54Z")

</div>

This sounds unrelated to our Enterprise Search or App Search products. Reassigning to elasticsearch.

---

<div class="post-metadata">

**Author:** ![filmac79](https://avatars.discourse-cdn.com/v4/letter/f/a4c791/32.png) [@filmac79](https://discuss.elastic.co/u/filmac79)\
**Post date:** [January 25, 2021, 5:18pm UTC](https://discuss.elastic.co/t/pagination-with-highlevelrestclient/262146/3 "2021-01-25T17:18:40Z")

</div>

Thanks @JasonStoltz, sorry my bad, I chose the wrong category ☹

---

<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:** [January 25, 2021, 9:22pm UTC](https://discuss.elastic.co/t/pagination-with-highlevelrestclient/262146/4 "2021-01-25T21:22:51Z")

</div>

> [@filmac79](#):
>
> but I don´t see any PIT (point in time) parameter.

Yeah. True. See also the discussion at [How to make Point In Time API request using JAVA REST High Level Client](https://discuss.elastic.co/t/how-to-make-point-in-time-api-request-using-java-rest-high-level-client/260965)

---

<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:** [January 25, 2021, 9:25pm UTC](https://discuss.elastic.co/t/pagination-with-highlevelrestclient/262146/5 "2021-01-25T21:25:06Z")

</div>

You can use:

- the [`size` and `from` parameters](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-from-size.html) to display by default up to 10000 records to your users. If you want to change this limit, you can change `index.max_result_window` setting but be aware of the consequences (ie memory).
- the [search after](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-search-after.html) feature to do deep pagination.
- the [Scroll API](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html) if you want to extract a resultset to be consumed by another tool later.

The same applies to the rest client 😉

---

<div class="post-metadata">

**Author:** ![filmac79](https://avatars.discourse-cdn.com/v4/letter/f/a4c791/32.png) [@filmac79](https://discuss.elastic.co/u/filmac79)\
**Post date:** [January 25, 2021, 10:38pm UTC](https://discuss.elastic.co/t/pagination-with-highlevelrestclient/262146/6 "2021-01-25T22:38:59Z")

</div>

Hello @dadoonet, thanks for your reply. Not sure I understood the part related to PIT, the link points to this thread again. Did you mean another thread? In that case, could you please fix it?

---

<div class="post-metadata">

**Author:** ![filmac79](https://avatars.discourse-cdn.com/v4/letter/f/a4c791/32.png) [@filmac79](https://discuss.elastic.co/u/filmac79)\
**Post date:** [January 25, 2021, 10:45pm UTC](https://discuss.elastic.co/t/pagination-with-highlevelrestclient/262146/7 "2021-01-25T22:45:34Z")

</div>

Also, @dadoonet which is your advice? Which is the best practice?  
I need to go over all the results for a query (it's a percolate query, just to provide you one more detail) and I would like the pagination to be consistent even if in the meantime changes happen. Should I use scroll or search after from the HighLevelRestClient?  
Thanks!

---

<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:** [January 26, 2021, 6:18am UTC](https://discuss.elastic.co/t/pagination-with-highlevelrestclient/262146/8 "2021-01-26T06:18:17Z")

</div>

😱 Fixed

---

<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:** [January 26, 2021, 6:18am UTC](https://discuss.elastic.co/t/pagination-with-highlevelrestclient/262146/9 "2021-01-26T06:18:47Z")

</div>

I'd use the scroll API.

---

<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:** [February 23, 2021, 6:19am UTC](https://discuss.elastic.co/t/pagination-with-highlevelrestclient/262146/10 "2021-02-23T06:19:01Z")

</div>

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