BM25 is Elasticsearch’s default similarity algorithm for full-text search. It assigns each matching document a positive floating-point _score, then returns higher-scoring documents first. The score reflects how well a document matches the query, helping a search for a book such as “Java” rank likely matches ahead of weaker ones. section 2.3.4 section 3.4.1
BM25 improves on TF-IDF in two practical ways. It accounts for term frequency, so a query term appearing in a document can raise relevance, but uses nonlinear saturation so repeated terms do not gain unlimited credit. It also normalizes for document length, reducing the advantage that longer documents might otherwise receive simply because they contain more words. section 3.4.2
Why short titles can rank higher
For a title search for “Java,” Effective Java can receive a higher score than Head First Java even though both match: the query word occupies a shorter field. A title with several occurrences, such as “Mastering Java: Learning Core Java and Enterprise Java With Examples,” may gain relevance from frequency, while BM25 prevents repetition alone from dominating the ranking. section 3.4.1 section 3.4.2
Table 3.5 Elasticsearch’s similarity algorithms (view table figure)
Compare BM25 with Elasticsearch’s other built-in similarity algorithms when the default ranking behavior does not fit a field’s search requirements. section 3.4.2
Similarity is applied per field through mapping APIs. Elasticsearch can use alternatives to BM25 or custom similarity settings when needed; BM25 exposes k1 for nonlinear term-frequency saturation and b for document-length normalization, with defaults of 1.2 and 0.75. section 3.4.2
NOTE: A _score is relative relevance within a result set: the highest score is normally reported as max_score and belongs to the first result. Treat BM25 as a ranking mechanism for matching documents, then evaluate whether its ordering fits the search experience. section 3.4.1




