# Unexpected scoring with nested objects

**URL:** <https://discuss.elastic.co/t/unexpected-scoring-with-nested-objects/50694>\
**Category:** Elasticsearch\
**Created:** [May 23, 2016, 10:35am UTC](https://discuss.elastic.co/t/unexpected-scoring-with-nested-objects/50694 "2016-05-23T10:35:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chris67](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chris67/32/9870_2.png) [@chris67](https://discuss.elastic.co/u/chris67)\
**Post date:** [May 23, 2016, 10:35am UTC](https://discuss.elastic.co/t/unexpected-scoring-with-nested-objects/50694/1 "2016-05-23T10:35:34Z")

</div>

I have a system containing documents, each of which has a set of tags. The tags are stored as nested objects and I am querying for documents based on the tags. I would like documents that match more tags to be scored higher. This is mostly working fine, but I have seen some cases where the scoring is not as expected.

In this gist:[nestedTestScore.sh](https://gist.github.com/nespera/af5c30a82a50f266870b53d1fb46874a) I create an index, and insert four documents, each with a single tag, "aaaa", "bbbb", "cccc" and "dddd". I then query for documents with tags "aaaa" or "bbbb". What I see is that the first two documents are returned, but with quite different scores.

If I change the script and only insert the first two documents, then they do indeed get returned with the same score. I have tried this against ElasticSearch 2.1.1 and 2.3.3 with the same results.

Can anyone explain what is going on here?

Thanks

Chris

---

<div class="post-metadata">

**Author:** ![chris67](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chris67/32/9870_2.png) [@chris67](https://discuss.elastic.co/u/chris67)\
**Post date:** [May 24, 2016, 10:19am UTC](https://discuss.elastic.co/t/unexpected-scoring-with-nested-objects/50694/2 "2016-05-24T10:19:11Z")

</div>

I don't really understand what is happening, but I have worked around the problem. What I really care about is the number of matching tags and so TF/IDF is irrelevant. Following the details here: [Ignoring TF/IDF](https://www.elastic.co/guide/en/elasticsearch/guide/current/ignoring-tfidf.html) I wrapped each of the term queries in a constant\_score query. This resulted in the scoring working as expected.

---

<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:** [July 5, 2017, 10:49pm UTC](https://discuss.elastic.co/t/unexpected-scoring-with-nested-objects/50694/3 "2017-07-05T22:49:32Z")

</div>


