Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Saved searches and filters
📖 Scenario: You work at a company that stores product data in Elasticsearch. You want to save common searches and filters to quickly find products later.
🎯 Goal: Build saved search queries with filters in Elasticsearch JSON format.
📋 What You'll Learn
Create an Elasticsearch query with a match_all base
Add a filter for products with price less than 100
Save the filter as a named filter called 'cheap_products'
Print the final saved search JSON
💡 Why This Matters
🌍 Real World
Saved searches and filters help users quickly find relevant data without rewriting queries every time.
💼 Career
Elasticsearch developers and data engineers often create and manage saved searches and filters for efficient data retrieval.
Progress0 / 4 steps
1
Create the base query
Create a variable called saved_search and set it to an Elasticsearch query JSON with a query key containing {"match_all": {}}.
Elasticsearch
Hint
Use a dictionary with keys 'query' and inside it 'match_all' with an empty object.
2
Add a price filter
Add a post_filter key at the top level of saved_search with a range filter on price less than 100. Use the exact structure: {"range": {"price": {"lt": 100}}}.
Elasticsearch
Hint
Use the post_filter key at the top level with the range filter inside.
3
Save the filter as a named filter
Wrap the filter inside a bool query with a filter list containing the range filter. Name the filter cheap_products by adding "_name": "cheap_products" inside the range filter. Update saved_search["query"] to this new bool query.
Elasticsearch
Hint
Use a bool query with a filter list and add the _name key inside the range filter.
4
Print the saved search JSON
Print the saved_search variable to display the final saved search JSON.
Elasticsearch
Hint
Use print(saved_search) to show the JSON.
Practice
(1/5)
1. What is the main purpose of a saved search in Elasticsearch?
easy
A. To create visual charts from data
B. To store raw data permanently
C. To reuse a query easily without rewriting it every time
D. To delete old data automatically
Solution
Step 1: Understand what saved searches do
Saved searches store queries so you can run them again without rewriting.
Step 2: Compare options to this purpose
Only To reuse a query easily without rewriting it every time describes reusing queries easily, which matches saved searches.
Final Answer:
To reuse a query easily without rewriting it every time -> Option C
Quick Check:
Saved searches = reuse queries [OK]
Hint: Saved searches store queries for reuse, not data or visuals [OK]
Common Mistakes:
Confusing saved searches with data storage
Thinking saved searches create charts
Assuming saved searches delete data
2. Which of the following is the correct JSON structure to apply a filter in a saved search?
easy
A. {"query": {"match_all": {}}, "filter": {"term": {"status": "active"}}}
B. {"query": {"filtered": {"filter": {"term": {"status": "active"}}}}}
C. {"query": {"term": {"status": "active"}}}
D. {"filter": {"match": {"status": "active"}}}
Solution
Step 1: Recall filter syntax in Elasticsearch saved searches
Filters are applied inside a filtered query using the "filtered" key.
Step 2: Check each option's structure
{"query": {"filtered": {"filter": {"term": {"status": "active"}}}}} correctly uses "query": {"filtered": {"filter": {...}}} which is the right way to apply filters.
Final Answer:
{"query": {"filtered": {"filter": {"term": {"status": "active"}}}}} -> Option B
The JSON snippet ends without closing all opened braces, causing syntax error.
Step 2: Verify other parts are valid
Using 'term' filter and 'match' query inside filtered is correct syntax.
Final Answer:
Missing closing braces at the end -> Option D
Quick Check:
JSON must be properly closed [OK]
Hint: Count opening and closing braces to spot JSON errors [OK]
Common Mistakes:
Ignoring missing braces causing syntax errors
Thinking 'term' filter is wrong here
Assuming filters can't be inside queries
5. You want to create a saved search that filters documents where 'status' is 'active' and 'priority' is either 'high' or 'medium'. Which JSON filter correctly represents this?