0
0
Elasticsearchquery~30 mins

Relevance score (_score) in Elasticsearch - Mini Project: Build & Apply

Choose your learning style9 modes available
Understanding Relevance Score (_score) in Elasticsearch
📖 Scenario: You are building a simple search feature for a small online bookstore. You want to understand how Elasticsearch ranks search results using the _score field, which shows how relevant each book is to the search query.
🎯 Goal: Learn how to perform a basic search query in Elasticsearch and see how the _score helps rank the results by relevance.
📋 What You'll Learn
Create an Elasticsearch index with sample book data
Add a search query to find books by title
Retrieve and display the _score for each search result
Understand how _score affects the order of results
💡 Why This Matters
🌍 Real World
Search engines use relevance scores to show the most useful results first, like when you search for books, products, or articles online.
💼 Career
Understanding _score helps developers build better search features that give users the best matches quickly.
Progress0 / 4 steps
1
Create an Elasticsearch index with sample book data
Create an index called books and add these three documents with fields title and author: {"title": "Learn Elasticsearch", "author": "Alice"}, {"title": "Mastering Search", "author": "Bob"}, {"title": "Elasticsearch Basics", "author": "Charlie"}.
Elasticsearch
Need a hint?

Use the PUT method to add documents to the books index with the exact titles and authors given.

2
Add a search query to find books by title
Create a search query that looks for the word Elasticsearch in the title field of the books index.
Elasticsearch
Need a hint?

Use the GET method with _search and a match query on the title field.

3
Retrieve and display the _score for each search result
Modify the search query to include the _score field in the results and show it for each matching document.
Elasticsearch
Need a hint?

Add "explain": true to the search request to see the _score details for each hit.

4
Print the search results with their relevance scores
Run the search query and print the title and _score of each hit in the results.
Elasticsearch
Need a hint?

Look at the search response hits and print each hit's _source.title and _score.