Relevance and BM25
Why these ten documents came back in this order, and how to make the engine tell you.
Open this lesson in the learning hubKey points
- BM25 has been the default similarity since 5.0, replacing the classic TF-IDF implementation.
- Three inputs decide a score: term frequency, inverse document frequency, and field length.
- Term frequency saturates, so the tenth occurrence of a word adds far less than the second.
- A rare term is worth more, because idf rises as the number of documents holding it falls.
- The same hit in a short title outranks it in a long body, thanks to length normalisation.
k1defaults to 1.2 andbto 0.75, and the explain API shows every factor.
Example
GET /articles/_search
{
"query": { "match": { "title": "elasticsearch tuning" } },
"explain": true
}
GET /articles/_explain/7
{ "query": { "match": { "title": "elasticsearch tuning" } } }
# each term contributes: idf * (tf saturated by k1 and normalised by b)
Rare terms in short fields score highest, and repetition saturates - run explain before tuning boosts.
This is a reading copy. The full lesson — with the visual explainer, the interactive lab and a Run button for the code — lives in the Elasticsearch Course course, and every lesson in it is listed on the Elasticsearch Course contents page.