# Elasticsearch Scoring Inconsistency

**URL:** <https://discuss.elastic.co/t/elasticsearch-scoring-inconsistency/291488>\
**Category:** Elasticsearch\
**Created:** [December 11, 2021, 12:30am UTC](https://discuss.elastic.co/t/elasticsearch-scoring-inconsistency/291488 "2021-12-11T00:30:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![powerte](https://avatars.discourse-cdn.com/v4/letter/p/c67d28/32.png) [@powerte](https://discuss.elastic.co/u/powerte)\
**Post date:** [December 11, 2021, 12:30am UTC](https://discuss.elastic.co/t/elasticsearch-scoring-inconsistency/291488/1 "2021-12-11T00:30:31Z")

</div>

Our API uses Elasticsearch to return results based on scoring (relevance). In our use case, it's important we consistently return documents in the same sort order. We currently see that queries with larger result sets (approx. \> 500 documents) return inconsistent scoring on successive runs despite no changes being made to the Elasticsearch indices.

The [elasticsearch documentation](https://www.elastic.co/guide/en/elasticsearch/reference/master/consistent-scoring.html) suggests scores are not reproducible and "The recommended way to work around this issue is to use a string that identifies the user that is logged in (a user id or session id for instance) as a [preference](https://www.elastic.co/guide/en/elasticsearch/reference/master/search-search.html#search-preference). This ensures that all queries of a given user are always going to hit the same shards, so scores remain more consistent across queries."

However, despite using something like `preference: foo` and `search_type: dfs_query_then_fetch` in the query, we're still receiving inconsistent scoring, and because of this our API results are not ordered deterministically from request to request.

The cluster we're working with is relatively simple. It has two nodes--the primary shard for the index in question lives on node A and the replica lives on node B. When we specify a `_prefer_nodes` setting or the now-deprecated `_primary_first` in the `preference` query, we seem to receive the consistent scoring/sort-ordering we're looking for.

We would expect that using the documentation-prescribed approach of `preference: <arbitrary_string>` would resolve the scoring inconsistency, and we'd prefer not having to layer on application-level logic for detecting which nodes have serviced queries with particular parameters and then specifying the node that has historically served a request using `_prefer_nodes` in order to get the consistent sort order.

Can someone help us to better understand why `preference` isn't working for us in the way we expect and if there's a more generally-accepted way of achieving consistent sort order via query definition or cluster configuration?

---

<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:** [January 8, 2022, 12:31am UTC](https://discuss.elastic.co/t/elasticsearch-scoring-inconsistency/291488/2 "2022-01-08T00:31:07Z")

</div>

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