# Search\_after ideas

**URL:** <https://discuss.elastic.co/t/search-after-ideas/152909>\
**Category:** Elasticsearch\
**Created:** [October 17, 2018, 7:51pm UTC](https://discuss.elastic.co/t/search-after-ideas/152909 "2018-10-17T19:51:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![joropito](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joropito/32/32138_2.png) [@joropito](https://discuss.elastic.co/u/joropito)\
**Post date:** [October 17, 2018, 7:51pm UTC](https://discuss.elastic.co/t/search-after-ideas/152909/1 "2018-10-17T19:51:04Z")

</div>

As someone knows, size/from pagination isn't the best way to do paging with large results.  
I would like to use search\_after but allowing the user to set the page number so I would need the last document \_id for each page to do this.

Is there any way to get the "last document \_id" using some kind of aggregation?  
Like grouping by hit number and getting the last.

As an example, lets say I have 10 results per page, so I need \_id for results 10, 20, 30 and so on.  
Maybe with some scripted field?

I'm not sure where to go with this.

Thanks in advance

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [October 18, 2018, 7:18am UTC](https://discuss.elastic.co/t/search-after-ideas/152909/2 "2018-10-18T07:18:30Z")

</div>

I am not a hundred percent sure what you are after here. Neither from/size nor search\_after pagination is stable in a sense, that current modifications to the index will also change the order.

I am still unsure what exactly your use-case is. Maybe you can elaborate without mentioning any elasticsearch technology.

Also, you may want to look at scroll searches, if you want to have a point in time snapshot.

--Alex

---

<div class="post-metadata">

**Author:** ![klof](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/klof/32/31590_2.png) [@klof](https://discuss.elastic.co/u/klof)\
**Post date:** [October 18, 2018, 7:27am UTC](https://discuss.elastic.co/t/search-after-ideas/152909/3 "2018-10-18T07:27:38Z")

</div>

My take is, if you want to have the page numbers, you should go with `from/size` parameters, and in the UI, you will have a max page (to be defined based on your `from` and the `index.max_result_window`) to avoid to reach the elasticsearch limitation.

The `search_after` is nice, if you want indeed to parse all the results, but mainly when the UI has a "show next" button.

---

<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:** [November 15, 2018, 7:40am UTC](https://discuss.elastic.co/t/search-after-ideas/152909/4 "2018-11-15T07:40:48Z")

</div>

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