# More Examples of 'search\_after'?

**URL:** <https://discuss.elastic.co/t/more-examples-of-search-after/171553>\
**Category:** Elasticsearch\
**Created:** [March 8, 2019, 8:24pm UTC](https://discuss.elastic.co/t/more-examples-of-search-after/171553 "2019-03-08T20:24:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![avocado](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@avocado](https://discuss.elastic.co/u/avocado)\
**Post date:** [March 8, 2019, 8:24pm UTC](https://discuss.elastic.co/t/more-examples-of-search-after/171553/1 "2019-03-08T20:24:03Z")

</div>

Please excuse me for being obtuse, but the explanation of how the 'search\_after' query works is completely confusing to me

[https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-search-after.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-search-after.html)

I don't really understand what these numbers are and how do they relate to other examples of queries one might use?  
"search\_after": [1463538857, "654323"],

Any help or examples in a different context will be much appreciated! Aloha 🌺🤙

---

<div class="post-metadata">

**Author:** ![avocado](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@avocado](https://discuss.elastic.co/u/avocado)\
**Post date:** [March 8, 2019, 8:33pm UTC](https://discuss.elastic.co/t/more-examples-of-search-after/171553/2 "2019-03-08T20:33:17Z")

</div>

Google answered my question, and indeed I was missing something obvious. For others who are wondering here is a very clear example (something like this could make the ES docs a little more clear):

- If there are 31 annotations—1 for each day in October—the search parameter combination of `sort` =updated, `order` =desc, `limit` =10, and `search_after` =2018-10-05 will retrieve annotations made from the 6th of October to the 16th of October.
- If there are 31 annotations with IDs 0-31, the search parameter combination of `sort` =id, `order` =asc, `limit` =10, and `search_after` =5, will return the annotations with IDs 6-16.

Searching using `offset` and `limit` is inefficient because elasticsearch must load all the annotations ( `offset` + `limit` number of annotations) into memory and sort them before returning the window of annotations defined by `offset` and `limit` . `search_after` does not require all the annotations to be loaded and sorted because it can be applied as a filter on the search query itself—as opposed to `offset` , which must be applied after the initial search. This is why `search_after` is more efficient and, while the old parameter `offset` does remain, it is not recommended to use it.

> **[New Search API Parameter: search\_after](https://web.hypothes.is/blog/new-search-api-parameter-search_after/)**
>
> Occasionally, there is a need to search for and return a large number of annotations. Previously, Hypothesis’ API made use of a parameter called offset that allowed the user to skip a number of initial annotations. By using offset, users could search...

---

<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:** [April 5, 2019, 8:46pm UTC](https://discuss.elastic.co/t/more-examples-of-search-after/171553/3 "2019-04-05T20:46:32Z")

</div>

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