# Different sorted result on same shard on different nodes

**URL:** https://discuss.elastic.co/t/different-sorted-result-on-same-shard-on-different-nodes/208783
**Category:** Elasticsearch
**Created:** [November 20, 2019, 10:09pm UTC](https://discuss.elastic.co/t/different-sorted-result-on-same-shard-on-different-nodes/208783 "2019-11-20T22:09:50Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![francesco1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/francesco1/32/58062_2.png) [@francesco1](https://discuss.elastic.co/u/francesco1)
#### Post date: [November 20, 2019, 10:09pm UTC](https://discuss.elastic.co/t/different-sorted-result-on-same-shard-on-different-nodes/208783/1 "2019-11-20T22:09:50Z")

</div>

I have a cluster with 2 data nodes, each node has one shard. When I make a query, I sort by a date field but I get inconsistent result if I perform the same query twice.

This is because (I think) ES hits the nodes in round-robin, and each node sorts the data slightly differently. Using `preference: my_user_id` doesn't help because I already hit the only available shard every time, it looks like the data in the shard is not the same across nodes. In fact, if I always hit a single node using `preference: "_prefer_nodes:orgKQBy5TyGcduyZ2MEVUw"` I get consistently sorted results.

How could I get a consistent sort without forcing my query on a specific node ? Aren't the shards identical across nodes ? Would the use of an additional tie-breaker sort help ?

thanks!

---

<div class="post-metadata">

### Author: ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)
#### Post date: [November 22, 2019, 6:51pm UTC](https://discuss.elastic.co/t/different-sorted-result-on-same-shard-on-different-nodes/208783/2 "2019-11-22T18:51:15Z")

</div>

When you say that there is an inconsistent sort order, do you mean for documents with the same date? If two documents have the same date, then the secondary sort order can be different on different shard copies.

If you have some sort of unique value in every document, you could use that as the secondary sort criterion to get to a consistent order.

---

<div class="post-metadata">

### Author: ![francesco1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/francesco1/32/58062_2.png) [@francesco1](https://discuss.elastic.co/u/francesco1)
#### Post date: [November 28, 2019, 1:22pm UTC](https://discuss.elastic.co/t/different-sorted-result-on-same-shard-on-different-nodes/208783/3 "2019-11-28T13:22:43Z")

</div>

Thanks for the suggestion @abdon, adding a unique sorting value did the trick!

---

<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: [December 26, 2019, 1:22pm UTC](https://discuss.elastic.co/t/different-sorted-result-on-same-shard-on-different-nodes/208783/4 "2019-12-26T13:22:47Z")

</div>

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