liveBook · Manning

Inverse document frequency

As explained in Elasticsearch in Action, Second Edition

Inverse document frequency measures how uncommon a term is across a document collection, giving rarer terms greater weight.

Inverse document frequency (IDF) measures whether a search term is common or rare across an indexed collection. In term frequency–inverse document frequency (TF-IDF), a term that appears often in one document but rarely across the collection receives more relevance weight. section 3.4.2

IDF contributes to relevance alongside other signals:

  • Term frequency (TF) measures occurrences within a document; higher frequency can increase relevance. section 3.4.2
  • Document frequency reflects collection-wide occurrence; higher document frequency lowers relevance under TF-IDF. section 3.4.2
  • BM25 improves on TF-IDF by limiting repeated-term effects and normalizing for document length. section 3.4.2

Inspect IDF in a movie search score

Run a match query with "explain": true to expose scoring details. For a search such as title: "Lord", the explanation identifies how many documents contain the term (n), the total document count (N), and the IDF contribution to the score. section 8.8.3

Listing 8.20 Asking the engine to explain the score
GET movies/_search
{
  "explain": true, 
  "_source": false, 
  "query": {
    "match": {
      "title": "Lord"
    }
  }
}

Use the explain-enabled search request to inspect the engine’s score calculation instead of treating relevance as a black box. section 8.8.3

IDF is one component of Elasticsearch relevance scoring. Similarity algorithms apply scoring per field, and BM25 is the default algorithm; alternative or customized similarity choices are available when default ranking does not fit the requirement. section 3.4.2 section 3.4.1

How Elasticsearch in Action, Second Edition covers it

How deep it goes
Defines IDF through collection-wide term occurrence and exposes its score calculation, while deferring customized similarity algorithms.
Examples
Uses Java book-title searches and an explain-enabled movie-title query for “Lord.”
What you can do after
Diagnose/debug with Elasticsearch explain output by checking IDF, term frequency, and matching calculations behind a score.
How it connects
Connects IDF to term frequency, TF-IDF, BM25, document length normalization, similarity, and relevance scoring.

Also explained in

Compare how 4 books explain inverse document frequency →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Elasticsearch in Action, Second Edition. The section links point to the parts of the book it draws on.