What if you could flip through millions of items instantly without waiting?
Why Search after for efficient pagination in Elasticsearch? - Purpose & Use Cases
Imagine you have a huge list of products in an online store. You want to show customers page by page, but each time you ask the system to find page 10 or 20, it has to count and skip all the previous items first.
This manual way is slow because the system must look through all earlier pages again and again. It also uses a lot of memory and can cause delays, making customers wait longer and feel frustrated.
Using search after lets the system remember where it left off. Instead of counting from the start every time, it jumps directly to the next set of results, making pagination fast and smooth even with millions of items.
GET /products/_search
{
"from": 1000, "size": 10,
"query": { "match_all": {} }
}GET /products/_search
{
"size": 10,
"search_after": ["last_sort_value"],
"sort": ["price"]
}This technique enables lightning-fast page navigation through huge data sets without slowing down or crashing.
Think of scrolling through thousands of social media posts or product reviews where you want instant loading of the next page without waiting.
Manual pagination with offsets is slow and resource-heavy.
Search after jumps directly to the next page using the last item's sort value.
This makes browsing large data sets fast and user-friendly.