# Accessing end of dataset with search\_after

**URL:** <https://discuss.elastic.co/t/accessing-end-of-dataset-with-search-after/298212>\
**Category:** Elasticsearch\
**Created:** [February 24, 2022, 7:33pm UTC](https://discuss.elastic.co/t/accessing-end-of-dataset-with-search-after/298212 "2022-02-24T19:33:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![TonyxSun](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tonyxsun/32/102299_2.png) [@TonyxSun](https://discuss.elastic.co/u/TonyxSun)\
**Post date:** [February 24, 2022, 7:33pm UTC](https://discuss.elastic.co/t/accessing-end-of-dataset-with-search-after/298212/1 "2022-02-24T19:33:01Z")

</div>

Hello,

We are using search\_after to populate and paginate a data grid using fetch requests from an index with around 200,000 documents. We would like to include a "jump to last page" button in our table, but search\_after does not give access to random data fetching. I am not sure how/if there is a way to access the last block of data to populate the last page of our data table.

The data itself does not change but I need to make new requests depending on sorting parameters. The last block/page always comes after the nth document since the size of the data doesn't change between sorts, but I don't have a way to know what the nth document is, to fetch the block starting at n + 1.

Using what scarce resources there are online, the only solution I've found is to build a "pagination\_index", ie an list of the search\_after values (referencing last document in a block) for each block. If I want to access the nth block, then I will use pagination\_index[n-1] as the search after value. Building this pagination\_index will require fetching all the blocks of data, taking the last document's sort value, and constructing an array, which takes time and resources. Are there any other solutions to this problem?

Thanks for any help and let me know if any part is unclear

---

<div class="post-metadata">

**Author:** ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)\
**Post date:** [February 26, 2022, 2:04am UTC](https://discuss.elastic.co/t/accessing-end-of-dataset-with-search-after/298212/2 "2022-02-26T02:04:22Z")

</div>

There is no feature in Elasticsearch to access any pages of the search results. It is explicitly explained in the point in time API page. If you need only the last page, one trick could be get the first page of up-side-down order.

---

<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 26, 2022, 2:04am UTC](https://discuss.elastic.co/t/accessing-end-of-dataset-with-search-after/298212/3 "2022-03-26T02:04:33Z")

</div>

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