# Sort Order when relevance is equal

**URL:** <https://discuss.elastic.co/t/sort-order-when-relevance-is-equal/17496>\
**Category:** Elasticsearch\
**Created:** [May 14, 2014, 12:49am UTC](https://discuss.elastic.co/t/sort-order-when-relevance-is-equal/17496 "2014-05-14T00:49:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Erich\_Lin](https://avatars.discourse-cdn.com/v4/letter/e/85e7bf/32.png) [@Erich\_Lin](https://discuss.elastic.co/u/Erich_Lin)\
**Post date:** [May 14, 2014, 12:49am UTC](https://discuss.elastic.co/t/sort-order-when-relevance-is-equal/17496/1 "2014-05-14T00:49:55Z")

</div>

Ignoring the bouncing results problem with multiple shards , is the order  
of results deterministic when sorting by relevance score or any other  
field.

What I mean by this is if two documents have the same score,

1. will they always be in the same order if we set the preference parameter  
to an arbitrary string like the user’s session ID.
2. If so, is there a way to predict this deterministic order? Is it done by  
ID of the documents as a tiebreaker etc?
3. If not, could we specify that or do we have to do a secondary sort on ID  
if we wanted to do that?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/490e4f7f-ce26-4a5f-abe5-9df28b71ddc9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/490e4f7f-ce26-4a5f-abe5-9df28b71ddc9%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Mateusz\_Kaczynski\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mateusz_kaczynski_2/32/1236_2.png) [@Mateusz\_Kaczynski\_2](https://discuss.elastic.co/u/Mateusz_Kaczynski_2)\
**Post date:** [July 21, 2014, 5:00pm UTC](https://discuss.elastic.co/t/sort-order-when-relevance-is-equal/17496/2 "2014-07-21T17:00:16Z")

</div>

Seconding question.

Also, is it possible that the default order for an equal relevance score  
changed between 1.0 and 1.2 ? We've noticed seemingly random ordering in  
our regression when updating.

On Wednesday, 14 May 2014 00:49:55 UTC, Erich Lin wrote:

> Ignoring the bouncing results problem with multiple shards , is the order  
> of results deterministic when sorting by relevance score or any other  
> field.
> 
> What I mean by this is if two documents have the same score,
> 
> 1. will they always be in the same order if we set the preference  
> parameter to an arbitrary string like the user’s session ID.
> 2. If so, is there a way to predict this deterministic order? Is it done  
> by ID of the documents as a tiebreaker etc?
> 3. If not, could we specify that or do we have to do a secondary sort on  
> ID if we wanted to do that?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/dd34df9d-7ef0-4fec-9f50-2a7e30cfae8e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/dd34df9d-7ef0-4fec-9f50-2a7e30cfae8e%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Mateusz\_Kaczynski\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mateusz_kaczynski_2/32/1236_2.png) [@Mateusz\_Kaczynski\_2](https://discuss.elastic.co/u/Mateusz_Kaczynski_2)\
**Post date:** [July 21, 2014, 5:11pm UTC](https://discuss.elastic.co/t/sort-order-when-relevance-is-equal/17496/3 "2014-07-21T17:11:02Z")

</div>

Seconding question.

Also, is it possible that it changed between versions 1.0 and 1.2? We're  
trying to upgrade and noticed a seemingly random order of documents with  
equal relevance in regression testing.

On Wednesday, 14 May 2014 00:49:55 UTC, Erich Lin wrote:

> Ignoring the bouncing results problem with multiple shards , is the order  
> of results deterministic when sorting by relevance score or any other  
> field.
> 
> What I mean by this is if two documents have the same score,
> 
> 1. will they always be in the same order if we set the preference  
> parameter to an arbitrary string like the user’s session ID.
> 2. If so, is there a way to predict this deterministic order? Is it done  
> by ID of the documents as a tiebreaker etc?
> 3. If not, could we specify that or do we have to do a secondary sort on  
> ID if we wanted to do that?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/284b6bfd-68aa-4717-ab52-73d44f7cc196%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/284b6bfd-68aa-4717-ab52-73d44f7cc196%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [July 22, 2014, 6:02am UTC](https://discuss.elastic.co/t/sort-order-when-relevance-is-equal/17496/4 "2014-07-22T06:02:45Z")

</div>

Hi Erich

On 14 May 2014 02:49, Erich Lin [elin@onekingslane.com](mailto:elin@onekingslane.com) wrote:

> 1. will they always be in the same order if we set the preference  
> parameter to an arbitrary string like the user’s session ID.

They will be, until a merge happens (eg from indexing, updating, deleting,  
or just because...)

> 1. If so, is there a way to predict this deterministic order? Is it done  
> by ID of the documents as a tiebreaker etc?

It's the order of docs in the Lucene segment

> 1. If not, could we specify that or do we have to do a secondary sort on  
> ID if we wanted to do that?

Yes, you could provide a secondary sort on \_uid (not \_id)

> Also, is it possible that the default order for an equal relevance score  
> changed between 1.0 and 1.2 ? We've noticed seemingly random ordering in  
> our regression when updating.

It shouldn't have - if you can reproduce this, please open an issue.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAPt3XKTVcsuHG%3DPup7iPtZsFuX9Pp50SG-Ewor5Ns2WVY2PziQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAPt3XKTVcsuHG%3DPup7iPtZsFuX9Pp50SG-Ewor5Ns2WVY2PziQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [July 6, 2017, 1:14am UTC](https://discuss.elastic.co/t/sort-order-when-relevance-is-equal/17496/5 "2017-07-06T01:14:19Z")

</div>


