Relevance is acting strange on sort and _routing does not seem to help

I came across a strange issue with our elastic search index, where the same query with particular sorting returns different results. My index is on 4 shards and also in the mapping I have specified "_routing": { "required": true }. In the query I pass _routing as one of the terms { "term": { "_routing": xxx } }".

I came over this https://www.elastic.co/guide/en/elasticsearch/guide/current/relevance-is-broken.html, and if understand correctly this documentation basically states that I can see this behavior because of relevance being calculated on different shards differently just because of the number of documents on each shard.

Also, after readings this https://www.elastic.co/guide/en/elasticsearch/guide/current/routing-value.html, I believed that specifying _routing will route my document into one shard based on the value.

So my questions are:

  1. Why specifying ?search_type=dfs_query_then_fetch does not seem to change the behavior? I still see two different results for different requests.
  2. When I specify _routing value, all the documents in theory with the same _routing value supposed to come from the same shard? But why is the relevance still broken and I see different results every time I ran the query? It feels like documents with the same _routing can go to multiple shards, can this be true?

I see two different types of results. I have the index on 4 shards, 2 primary and 2 secondary.

I have figured this out, this was happening because index has 2 primary shards with 2 secondary shards. And primary and secondary shard calculated the score differently. What I ended up doing is setting preference=_primary.

https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-request-preference.html

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