0
0
Elasticsearchquery~30 mins

Why advanced search improves user experience in Elasticsearch - See It in Action

Choose your learning style9 modes available
Why advanced search improves user experience
📖 Scenario: Imagine you run an online bookstore. Customers want to find books quickly and easily. Basic search only looks for exact words, but advanced search can find books even if customers type different words or want to filter by price or author.
🎯 Goal: You will create a simple Elasticsearch query that shows how advanced search features like filtering and matching multiple fields improve the search experience for users.
📋 What You'll Learn
Create an Elasticsearch index with sample book data
Add a filter to search only books cheaper than a certain price
Use a multi-match query to search both title and author fields
Print the final Elasticsearch query JSON
💡 Why This Matters
🌍 Real World
Online stores and libraries use advanced search to help users find products or books quickly by filtering and searching multiple fields.
💼 Career
Understanding how to build advanced search queries is important for roles in data engineering, backend development, and search engine optimization.
Progress0 / 4 steps
1
Create sample book data
Create a variable called books that holds a list of three dictionaries. Each dictionary should have these keys and values exactly: 'title': 'The Great Gatsby', 'author': 'F. Scott Fitzgerald', 'price': 10; 'title': '1984', 'author': 'George Orwell', 'price': 15; 'title': 'To Kill a Mockingbird', 'author': 'Harper Lee', 'price': 12.
Elasticsearch
Need a hint?

Use a list with three dictionaries. Each dictionary has keys 'title', 'author', and 'price' with the exact values given.

2
Set a price filter
Create a variable called max_price and set it to 12. This will be used to filter books cheaper than or equal to this price.
Elasticsearch
Need a hint?

Just create a variable named max_price and assign it the number 12.

3
Build the advanced search query
Create a variable called search_query that holds a dictionary representing an Elasticsearch query. Use a bool query with a filter for price less than or equal to max_price, and a multi_match query inside must that searches the text 'great' in both title and author fields.
Elasticsearch
Need a hint?

Use a dictionary with 'query' key, inside it 'bool' with 'filter' for price range and 'must' for multi_match query on title and author.

4
Print the final search query
Write a print statement to display the search_query variable.
Elasticsearch
Need a hint?

Use print(search_query) to show the final query dictionary.