# Search score of identical documents changes when nested integer attribute is modified

**URL:** <https://discuss.elastic.co/t/search-score-of-identical-documents-changes-when-nested-integer-attribute-is-modified/281515>\
**Category:** Elasticsearch\
**Created:** [August 16, 2021, 8:23am UTC](https://discuss.elastic.co/t/search-score-of-identical-documents-changes-when-nested-integer-attribute-is-modified/281515 "2021-08-16T08:23:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guido\_Cioni](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guido_cioni/32/88028_2.png) [@Guido\_Cioni](https://discuss.elastic.co/u/Guido_Cioni)\
**Post date:** [August 16, 2021, 8:23am UTC](https://discuss.elastic.co/t/search-score-of-identical-documents-changes-when-nested-integer-attribute-is-modified/281515/1 "2021-08-16T08:23:28Z")

</div>

We stumbled upon this issue today and cannot really understand what is happening.  
Suppose we have a really simple index with just two documents inside that have the same contents.

```json
// document 1
{
    "question": "text of the question", 
 // nested part 
    "answers": [  
        {
            "text": "text of first answer",
            "clickscore": 0,
        },       
    ]
//
}

// document 2
{
    "question": "text of the question", 
 // nested part 
    "answers": [
        {
            "text": "text of first answer",
            "clickscore": 0,
        },       
    ]
//
}

```

`question` and `answers.text` are `Text` fields with the same analyzer defined on them. `answers` is a list with either 1 or many answers inside. `clickscore` is an `Integer` field that we will use in the future to boost the relevance of some documents. When we do a search we always look for matches in `question` and `answers.text`.

Now the weird part.

`document 1` and `document 2` have EXACTLY the same content, thus a search on the cluster with text contained in both `question` and `answers.text` (for example "text") returns hits with exactly the same score: makes sense.

However, if we update the `clickscore` of one of the two documents by setting e.g. the `document 2` `clickscore == 1` and we repeat EXACTLY the same search then the score of the documents are NOT the same.

How is this possible? `clickscore` is just an integer attribute and it should not affect the score of the search, especially since we're only looking for matches in the `Text` fields...

---

<div class="post-metadata">

**Author:** ![Guido\_Cioni](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guido_cioni/32/88028_2.png) [@Guido\_Cioni](https://discuss.elastic.co/u/Guido_Cioni)\
**Post date:** [August 30, 2021, 10:43am UTC](https://discuss.elastic.co/t/search-score-of-identical-documents-changes-when-nested-integer-attribute-is-modified/281515/2 "2021-08-30T10:43:47Z")

</div>

Apparently the problem is related to the fact that the shard statistics are not updated on time, and this causes the discrepancy.

If anyone arrives here on this question the only way to fix this is to manually perform a flush, so `Index('...').flush()` and the scores then are the same again.

---

<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:** [September 27, 2021, 10:44am UTC](https://discuss.elastic.co/t/search-score-of-identical-documents-changes-when-nested-integer-attribute-is-modified/281515/3 "2021-09-27T10:44:22Z")

</div>

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