# Why is idf different for same term in same field in same shard?

**URL:** <https://discuss.elastic.co/t/why-is-idf-different-for-same-term-in-same-field-in-same-shard/52383>\
**Category:** Elasticsearch\
**Created:** [June 9, 2016, 10:14pm UTC](https://discuss.elastic.co/t/why-is-idf-different-for-same-term-in-same-field-in-same-shard/52383 "2016-06-09T22:14:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![devj1988](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/devj1988/32/30628_2.png) [@devj1988](https://discuss.elastic.co/u/devj1988)\
**Post date:** [June 9, 2016, 10:14pm UTC](https://discuss.elastic.co/t/why-is-idf-different-for-same-term-in-same-field-in-same-shard/52383/1 "2016-06-09T22:14:35Z")

</div>

I am using the \_explain API to understand how 2 different documents ended up having different scores. I am surprised to see that for the same field and term, the idf for that term is different. The number of shards for this index is 1.

Here are the excerpts:

doc 1:

```
                    "value": 0.8311164,
                    "description": "weight(description:temperatur in 36) [PerFieldSimilarity], result of:",
                    "details": [
                      {
                        "value": 0.8311164,
                        "description": "score(doc=36,freq=1.0), product of:",
                        "details": [
                          {
                            "value": 0.3390907,
                            "description": "queryWeight, product of:",
                            "details": [
                              {
                                "value": 3.9216242,
                                "description": "idf(docFreq=6, maxDocs=130)",
                                "details": []
                              },
                              {
                                "value": 0.0864669,
                                "description": "queryNorm",
                                "details": []
                              }
                            ]
                          },

```

..........................

doc2

```
                    "value": 0.6850641,
                    "description": "weight(description:temperatur in 57) [PerFieldSimilarity], result of:",
                    "details": [
                      {
                        "value": 0.6850641,
                        "description": "score(doc=57,freq=1.0), product of:",
                        "details": [
                          {
                            "value": 0.3556344,
                            "description": "queryWeight, product of:",
                            "details": [
                              {
                                "value": 3.8526313,
                                "description": "idf(docFreq=5, maxDocs=104)",
                                "details": []
                              },
                              {
                                "value": 0.09230948,
                                "description": "queryNorm",
                                "details": []
                              }
                            ]
                          },

```

...................................

From "Relevance is broken", I understood that having multiple shards can cause this idf discrepancy. But, here I have only 1 shard.

As you can see from the excerpts, the maxDocs is different in both. How is it possible?

---

<div class="post-metadata">

**Author:** ![fguery](https://avatars.discourse-cdn.com/v4/letter/f/9e8a1a/32.png) [@fguery](https://discuss.elastic.co/u/fguery)\
**Post date:** [June 29, 2016, 10:04am UTC](https://discuss.elastic.co/t/why-is-idf-different-for-same-term-in-same-field-in-same-shard/52383/2 "2016-06-29T10:04:52Z")

</div>

Having the same problem here.  
I'm actually using different shards, but I'm setting both dfs\_query\_then\_fetch and preference; from my understanding it should be enough to avoid that issue according the the doc.

---

<div class="post-metadata">

**Author:** ![mkrakovyan](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@mkrakovyan](https://discuss.elastic.co/u/mkrakovyan)\
**Post date:** [August 25, 2016, 3:11pm UTC](https://discuss.elastic.co/t/why-is-idf-different-for-same-term-in-same-field-in-same-shard/52383/3 "2016-08-25T15:11:25Z")

</div>

Hi,  
both of you, probably, have the multi match query with cross\_fields type, smth like this

> " multi\_match": {  
> "query": "smth to search",  
> "type": "cross\_fields",  
> "fields": ["name^10", "name\_keywords^1.5", "description^0.7", "attr.text^0.7"]  
> }

In which case there's already an issue for that:  
[https://github.com/elastic/elasticsearch/issues/10346](https://github.com/elastic/elasticsearch/issues/10346)

Hope this helps and the issue will be resolved soon enough 🙂

---

<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:25pm UTC](https://discuss.elastic.co/t/why-is-idf-different-for-same-term-in-same-field-in-same-shard/52383/4 "2017-07-05T22:25:12Z")

</div>


