# Different IDF for different documents

**URL:** https://discuss.elastic.co/t/different-idf-for-different-documents/137726
**Category:** Elasticsearch
**Created:** [June 28, 2018, 3:25am UTC](https://discuss.elastic.co/t/different-idf-for-different-documents/137726 "2018-06-28T03:25:56Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![onami](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/onami/32/32755_2.png) [@onami](https://discuss.elastic.co/u/onami)
#### Post date: [June 28, 2018, 3:25am UTC](https://discuss.elastic.co/t/different-idf-for-different-documents/137726/1 "2018-06-28T03:25:56Z")

</div>

Hello,  
I'm trying to figure out why my documents are ranked the way they are, so here are two samples which are puzzling me.

The top result has docFreq = 45, docCount = 476 and weight(Synonym(descRu:лн descRu:ол descRu:олн) in 313).  
The second one has docFreq = 64, docCount = 527 and weight(Synonym(descRu:лн descRu:ол descRu:олн) in 324).

It doesn't make sense for me because I expect the IDF to be the same since it's the same term.

Hope you could explain what's the deal.

---

<div class="post-metadata">

### Author: ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)
#### Post date: [June 29, 2018, 1:23pm UTC](https://discuss.elastic.co/t/different-idf-for-different-documents/137726/2 "2018-06-29T13:23:52Z")

</div>

It's likely that they came from different shards. Term frequencies and IDFs are computed on a shard-local basis, which allows the search to happen in a coordination-free environment (the shards don't have to talk to each other and can execute in parallel).

Generally, this works fine because there is "enough data" to smooth out the discrepancies in TF/IDF, and scoring ends up being similar. But with few documents, or documents that aren't randomly distributed (e.g. using custom routing) you can run into more severe differences.

If you use DFS mode for search ([https://www.elastic.co/guide/en/elasticsearch/reference/6.2/search-request-search-type.html#dfs-query-then-fetch](https://www.elastic.co/guide/en/elasticsearch/reference/6.2/search-request-search-type.html#dfs-query-then-fetch)), this executes a pre-search phase which collects TFs and IDFs from all the shards, compiles a "global" set of statistics and uses that on each shard for scoring.

Scoring will be more "accurate" at the cost of an extra round trip and more work. Generally it's not needed though.

---

<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 27, 2018, 1:23pm UTC](https://discuss.elastic.co/t/different-idf-for-different-documents/137726/3 "2018-07-27T13:23:53Z")

</div>

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