0
0
Elasticsearchquery~5 mins

Relevance score (_score) in Elasticsearch

Choose your learning style9 modes available
Introduction

The relevance score (_score) helps you find the best matching documents for your search. It shows how well each result fits your query.

When you want to rank search results by how closely they match your keywords.
When you need to filter or sort documents based on their match quality.
When building a search feature that shows the most relevant items first.
Syntax
Elasticsearch
GET /index/_search
{
  "query": {
    "match": {
      "field": "search term"
    }
  }
}

The _score is automatically calculated for each document returned by the query.

You can use _score to sort or filter results.

Examples
Searches for products with the word "coffee" and returns results with a relevance score.
Elasticsearch
GET /products/_search
{
  "query": {
    "match": {
      "name": "coffee"
    }
  }
}
Searches multiple fields and scores documents based on how well they match "climate change".
Elasticsearch
GET /articles/_search
{
  "query": {
    "multi_match": {
      "query": "climate change",
      "fields": ["title", "content"]
    }
  }
}
Sorts books by how relevant they are to the author "Rowling", showing the best matches first.
Elasticsearch
GET /books/_search
{
  "query": {
    "match": {
      "author": "Rowling"
    }
  },
  "sort": [
    {"_score": "desc"}
  ]
}
Sample Program

This query searches the "library" index for documents with "adventure" in the title. Each result has a _score showing how well it matches.

Elasticsearch
GET /library/_search
{
  "query": {
    "match": {
      "title": "adventure"
    }
  }
}
OutputSuccess
Important Notes

A higher _score means a better match to your search query.

Scores depend on the query type and the data in your documents.

You can customize scoring with advanced queries, but the default is usually good for simple searches.

Summary

The _score shows how well each document matches your search.

Use it to sort or filter search results by relevance.

It helps users find the most useful information quickly.