AI Hints
Home›Elasticsearch Tutorial›Relevance and Scoring
Elasticsearch · Lesson 61 of 120

How Scoring Works

Why this result first?.

⏱ 2 min read▶ Video at 57:42🎓 Free
Watch this lesson in the Elasticsearch courseWatch on YouTube ↗Full Elasticsearch course

When ten products match, which one goes first? Elasticsearch gives each match a score, using a formula called BM25. Knowing its three ideas helps you fix bad rankings.

  • Ten matches
  • Which first?
  • BM25 score

Three ideas behind BM25

Term frequency. The more often a word appears in a document, the better, but with diminishing returns. Inverse document frequency. Rare words count more than common ones. And field length. A match in a short field counts more than in a long one.

Term frequencymore mentions, higher score
Inverse doc frequencyrare words count more
Field lengthshort fields count more

In the Trailhead catalog

Searching tent matches six product names, so tent is fairly common. Searching titanium matches one, so it's rare, and scores high. A match in the short name beats a match in the long description.

keyvalue
tentcommon, lower weight
titaniumrare, higher weight
In nameshort field, high
In descriptionlong field, lower

Summary

BM25 scores by term frequency, how rare the word is, and how short the field is. Next, asking Elasticsearch to explain a score.

Key takeaways
  • Term frequency
  • Rare words
  • Short fields
Next up: The explain API — show your working