0
0
Elasticsearchquery~30 mins

Why relevance scoring ranks results in Elasticsearch - See It in Action

Choose your learning style9 modes available
Understanding Why Relevance Scoring Ranks Results in Elasticsearch
📖 Scenario: You are building a simple search feature for a small online bookstore. You want to understand how Elasticsearch ranks search results based on relevance scoring.
🎯 Goal: Learn how Elasticsearch uses relevance scoring to rank search results by creating a small index, adding documents, configuring a search query, and observing how scores affect the order of results.
📋 What You'll Learn
Create an Elasticsearch index called books with fields title and description
Add three book documents with exact titles and descriptions
Configure a search query that searches the title field for the word adventure
Observe and understand how Elasticsearch ranks the results by their relevance scores
💡 Why This Matters
🌍 Real World
Search engines use relevance scoring to show the most useful results first, improving user experience.
💼 Career
Understanding relevance scoring is important for roles involving search engine optimization, data engineering, and backend development.
Progress0 / 4 steps
1
Create the books index with title and description fields
Create an Elasticsearch index called books with two text fields: title and description. Use the standard analyzer for both fields.
Elasticsearch
Need a hint?

Use the PUT method to create the index and define the mappings with title and description as text fields.

2
Add three book documents to the books index
Add these three documents to the books index with exact title and description values: 1. Title: "The Great Adventure", Description: "An exciting journey through unknown lands." 2. Title: "Adventure in the Mountains", Description: "A thrilling tale of mountain climbing." 3. Title: "Cooking Basics", Description: "Learn the essentials of cooking delicious meals."
Elasticsearch
Need a hint?

Use PUT /books/_doc/1, _doc/2, and _doc/3 to add each document with the exact titles and descriptions.

3
Create a search query to find books with adventure in the title
Write a search query using the match query on the title field to find documents containing the word adventure.
Elasticsearch
Need a hint?

Use a match query on the title field with the word adventure.

4
Observe how Elasticsearch ranks the results by relevance score
Add the explain parameter set to true in the search request to see how Elasticsearch calculates the relevance score for each result.
Elasticsearch
Need a hint?

Add ?explain=true to the search URL to see detailed scoring explanations.