Sort Order with Matching Values

Hello,

I have a document with an attribute called "rating", which is a manually
defined attribute created by the end-user. "rating" is indexed by
Elasticsearch as an integer. Sometimes, "rating" can be identical in
multiple documents. I sort the return of a search across those documents by
their "rating", descending.

So, unfortunately, Elasticsearch seems to sort documents with the same
"rating" differently across multiple queries. This is causing some user
experience issues.

In my first query, the document order may be:

{"name": "doca", "rating": 5}
{"name": "docb", "rating": 4}
{"name": "docc", "rating": 4}
{"name": "docd", "rating": 3}

And the second query:

{"name": "doca", "rating": 5}
{"name": "docc", "rating": 4}
{"name": "docb", "rating": 4}
{"name": "docd", "rating": 3}

Notice the position of docb and docc, in this case.

Can anyone suggest a way to return results in a consistent order in a
situation like this?

Thanks for your time.

Best,

Jack

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Hi Jack,

Sorting of document with equal sorting values is undefined (it depends on
the current state of lucene's segment which go through continuos merging)
.You will need to add a tie-breaking field for those situation. You can use
any field in your data or _score for the score of the document.
See Elasticsearch Platform — Find real-time answers at scale | Elastic for more
information.

Cheers,
Boaz

On Thursday, August 8, 2013 11:13:07 AM UTC+2, Jack Pearkes wrote:

Hello,

I have a document with an attribute called "rating", which is a manually
defined attribute created by the end-user. "rating" is indexed by
Elasticsearch as an integer. Sometimes, "rating" can be identical in
multiple documents. I sort the return of a search across those documents by
their "rating", descending.

So, unfortunately, Elasticsearch seems to sort documents with the same
"rating" differently across multiple queries. This is causing some user
experience issues.

In my first query, the document order may be:

{"name": "doca", "rating": 5}
{"name": "docb", "rating": 4}
{"name": "docc", "rating": 4}
{"name": "docd", "rating": 3}

And the second query:

{"name": "doca", "rating": 5}
{"name": "docc", "rating": 4}
{"name": "docb", "rating": 4}
{"name": "docd", "rating": 3}

Notice the position of docb and docc, in this case.

Can anyone suggest a way to return results in a consistent order in a
situation like this?

Thanks for your time.

Best,

Jack

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Boaz,

Thank you kindly, that solution to tie-break with another field worked
perfectly.

Best,

Jack

On Thu, Aug 8, 2013 at 1:47 PM, Boaz Leskes b.leskes@gmail.com wrote:

Hi Jack,

Sorting of document with equal sorting values is undefined (it depends on
the current state of lucene's segment which go through continuos merging)
.You will need to add a tie-breaking field for those situation. You can use
any field in your data or _score for the score of the document. See
Elasticsearch Platform — Find real-time answers at scale | Elastic for more
information.

Cheers,
Boaz

On Thursday, August 8, 2013 11:13:07 AM UTC+2, Jack Pearkes wrote:

Hello,

I have a document with an attribute called "rating", which is a manually
defined attribute created by the end-user. "rating" is indexed by
Elasticsearch as an integer. Sometimes, "rating" can be identical in
multiple documents. I sort the return of a search across those documents by
their "rating", descending.

So, unfortunately, Elasticsearch seems to sort documents with the same
"rating" differently across multiple queries. This is causing some user
experience issues.

In my first query, the document order may be:

{"name": "doca", "rating": 5}
{"name": "docb", "rating": 4}
{"name": "docc", "rating": 4}
{"name": "docd", "rating": 3}

And the second query:

{"name": "doca", "rating": 5}
{"name": "docc", "rating": 4}
{"name": "docb", "rating": 4}
{"name": "docd", "rating": 3}

Notice the position of docb and docc, in this case.

Can anyone suggest a way to return results in a consistent order in a
situation like this?

Thanks for your time.

Best,

Jack

--
You received this message because you are subscribed to a topic in the
Google Groups "elasticsearch" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/elasticsearch/VsHojLsvTUs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.