What is search_after pagination in Elasticsearch?

Answer

search_after is the recommended pagination method for deep pagination in live search UIs. Unlike from + size which becomes expensive for deep pages, search_after uses the sort values of the last document on the current page as a cursor for the next page. You must include a sort clause with a unique tiebreaker field (like _id). The next page request passes the last document's sort values in the search_after array. This approach is stateless (no scroll context to maintain) and performs consistently regardless of how deep the page is. It is ideal for infinite scroll UIs and cursor-based pagination APIs.