# Correct way to do tiebreaking with search\_after query without PIT

**URL:** https://discuss.elastic.co/t/correct-way-to-do-tiebreaking-with-search-after-query-without-pit/328941
**Category:** Elasticsearch
**Created:** [March 30, 2023, 1:05pm UTC](https://discuss.elastic.co/t/correct-way-to-do-tiebreaking-with-search-after-query-without-pit/328941 "2023-03-30T13:05:03Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![martsraits](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/martsraits/32/119204_2.png) [@martsraits](https://discuss.elastic.co/u/martsraits)
#### Post date: [March 30, 2023, 1:05pm UTC](https://discuss.elastic.co/t/correct-way-to-do-tiebreaking-with-search-after-query-without-pit/328941/1 "2023-03-30T13:05:03Z")

</div>

Hi

We use search\_after queries to support infinite scroll in the front end. Previously we used \_id field for sorting to keep consistent order. In newer versions of Elasticsearch it's not possible to use \_id field for sorting any more. What should be the preferred workaround?

I can see two options:

1. Copy \_id to some field in \_source which has doc\_values enabled. Today we rely on ids auto-generated by Elasticsearch. As I understand it is not possible to copy these ids automatically during indexing. We would need to start generating tiebreaker ids ourselves in the application.
2. Use search context with point in time to be able to use \_shard\_doc field. It would mean sending the pit id to frontend and back and predetermine search context duration. And actually we'd prefer not to preserve the index state so that new documents would also show up when scrolling.

So both options are complicated and the second one slightly changes behavior. Is there some better option which would suit our needs? For example could we somehow use doc\_values for \_id field or use \_shard\_doc field without search context or use copy\_to with \_id field?

Thanks.

---

<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 27, 2023, 1:05pm UTC](https://discuss.elastic.co/t/correct-way-to-do-tiebreaking-with-search-after-query-without-pit/328941/2 "2023-04-27T13:05:22Z")

</div>

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