# SearchAfter and possible duplicates?

**URL:** <https://discuss.elastic.co/t/searchafter-and-possible-duplicates/116058>\
**Category:** Elasticsearch\
**Created:** [January 18, 2018, 1:08pm UTC](https://discuss.elastic.co/t/searchafter-and-possible-duplicates/116058 "2018-01-18T13:08:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ryan\_M](https://avatars.discourse-cdn.com/v4/letter/r/b2d939/32.png) [@Ryan\_M](https://discuss.elastic.co/u/Ryan_M)\
**Post date:** [January 18, 2018, 1:08pm UTC](https://discuss.elastic.co/t/searchafter-and-possible-duplicates/116058/1 "2018-01-18T13:08:58Z")

</div>

I've been looking at the docs for [Search After](https://www.elastic.co/guide/en/elasticsearch/reference/6.1/search-request-search-after.html) and I have a question regarding the last paragraph (emphasis mine):

> search\_after is not a solution to jump freely to a random page but rather to scroll many queries in parallel. It is very similar to the scroll API but unlike it, the search\_after parameter is stateless, it is always resolved against the latest version of the searcher. **For this reason the sort order may change during a walk depending on the updates and deletes of your index.**

Does this mean that if I search with an ascending sort on a date and (during a walk) the first records date gets set to a date later than the last record in the sort, I'll receive the first record again?

---

<div class="post-metadata">

**Author:** ![Ryan\_M](https://avatars.discourse-cdn.com/v4/letter/r/b2d939/32.png) [@Ryan\_M](https://discuss.elastic.co/u/Ryan_M)\
**Post date:** [January 18, 2018, 1:50pm UTC](https://discuss.elastic.co/t/searchafter-and-possible-duplicates/116058/2 "2018-01-18T13:50:40Z")

</div>

I just did a test and found that you can have duplicates depending on your sort order.

For example, if you sort on an **\_id** then a **date** then the id is treated as a tiebreaker; so if the first record gets set to a later date then the last record it will not appear at the end.

OTOH if you sort on a **date** and then an **\_id** the first updated record will appear at the end of the set.

---

<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:** [February 15, 2018, 1:51pm UTC](https://discuss.elastic.co/t/searchafter-and-possible-duplicates/116058/3 "2018-02-15T13:51:04Z")

</div>

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