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

**URL:** <https://discuss.elastic.co/t/relevance-is-acting-strange-on-sort-and-routing-does-not-seem-to-help/107823>\
**Category:** Elasticsearch\
**Created:** [November 15, 2017, 8:35pm UTC](https://discuss.elastic.co/t/relevance-is-acting-strange-on-sort-and-routing-does-not-seem-to-help/107823 "2017-11-15T20:35:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Galim\_Kaudinov](https://avatars.discourse-cdn.com/v4/letter/g/e5b9ba/32.png) [@Galim\_Kaudinov](https://discuss.elastic.co/u/Galim_Kaudinov)\
**Post date:** [November 15, 2017, 8:35pm UTC](https://discuss.elastic.co/t/relevance-is-acting-strange-on-sort-and-routing-does-not-seem-to-help/107823/1 "2017-11-15T20:35:38Z")

</div>

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](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](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.

---

<div class="post-metadata">

**Author:** ![Galim\_Kaudinov](https://avatars.discourse-cdn.com/v4/letter/g/e5b9ba/32.png) [@Galim\_Kaudinov](https://discuss.elastic.co/u/Galim_Kaudinov)\
**Post date:** [November 15, 2017, 10:05pm UTC](https://discuss.elastic.co/t/relevance-is-acting-strange-on-sort-and-routing-does-not-seem-to-help/107823/2 "2017-11-15T22:05:43Z")

</div>

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](https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-request-preference.html)

---

<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 13, 2017, 10:05pm UTC](https://discuss.elastic.co/t/relevance-is-acting-strange-on-sort-and-routing-does-not-seem-to-help/107823/3 "2017-12-13T22:05:47Z")

</div>

Closed on December 13, 2017, 10:05pm UTC

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