How does relevance scoring work in Elasticsearch?

Answer

When Elasticsearch executes a full-text search query, it assigns each matching document a relevance score (the _score field) that represents how well the document matches the query. The scoring algorithm is BM25 (Best Match 25), the modern default replacing TF-IDF. BM25 considers term frequency (how often the search term appears in the document), inverse document frequency (how rare the term is across all documents — rare terms score higher), and field length normalization (shorter fields score higher). Results are returned sorted by score descending by default.