# Query on search\_after

**URL:** <https://discuss.elastic.co/t/query-on-search-after/142707>\
**Category:** Elasticsearch\
**Created:** [August 2, 2018, 7:55am UTC](https://discuss.elastic.co/t/query-on-search-after/142707 "2018-08-02T07:55:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sanjeebkdeka](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@sanjeebkdeka](https://discuss.elastic.co/u/sanjeebkdeka)\
**Post date:** [August 2, 2018, 7:55am UTC](https://discuss.elastic.co/t/query-on-search-after/142707/1 "2018-08-02T07:55:10Z")

</div>

Hi,

One of the column in my database has value of ascending order of time(basically session, so multiple documents belonging to that session have same value ).  
I have a requirement of deep scrolling[matches could be in range of millions]and i want the records to be retrieved in the ascending order of the session id.

I am considering of search\_after over others such as scroll etc and want to use document \_id as the tie breaker.

Snippet from search\_after documentation:

"A field with one unique value per document should be used as the tiebreaker of the sort specification. Otherwise the sort order for documents that have the same sort values would be undefined. The recommended way is to use the field \_id which is certain to contain one unique value for each document."

Wonder whether this would a way to go. Thank you for any valuable suggestion.

---

<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:** [August 2, 2018, 9:00am UTC](https://discuss.elastic.co/t/query-on-search-after/142707/2 "2018-08-02T09:00:11Z")

</div>

The `_id` will always be unique within a shard, as this is not the same as your session id.

So you probably would want to sort by time, session id and `_id`, if I understood you correctly.

--Alex

---

<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:** [August 30, 2018, 9:00am UTC](https://discuss.elastic.co/t/query-on-search-after/142707/3 "2018-08-30T09:00:12Z")

</div>

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