Search_after ideas

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

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.


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.

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