Order by a non timestamp parameter

Hi,

I am replacing our current search service based on MySQL query with a new service using Elasticsearch. I am running an integration test to make sure that all the existing query match with the new query using Elasticsearch and I noticed that when I order the result by a non timestamp field the result between mysql and ES mismatch.

Let say the order field used is price, I see that MySQL returns the results ordered by price and, if there are some results having the same price, it order the result using the created_at field as time breaker.

Elasticsearch has a different behavior to return the ordered field by price. Given that the _score parameter is null (I am not using any sort of scoring) at the moment, what is the parameter used by ES to perform the final order if the query returns multiple results with the same price.

Thanks in Advance,
Marco

you can sort by more than one parameter, and use the created_at field as a tie breaker in Elasticsearch as well - you have to specify it though.

--Alex

Thank you Alex for the fast reply!

What is the basic tie breaker used by Elasticsearch ?

...Because maybe it make more sense to my service to keep the ES tie breaker rather then use Mysql behavior...

Marco

if you don't specify one, there is none, so IIRC it is currently the order of indexing (but that is non guaranteed and not user friendly)

Ok, In that case I will explicitly add the the tie-breaker to the service.

Thanks again!

Marco

1 Like

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