0
0
Elasticsearchquery~30 mins

Range query in Elasticsearch - Mini Project: Build & Apply

Choose your learning style9 modes available
Range query
📖 Scenario: You have a collection of products in an online store. Each product has a price. You want to find products within a certain price range.
🎯 Goal: Build an Elasticsearch range query to find products priced between 50 and 150.
📋 What You'll Learn
Create an Elasticsearch index mapping with a price field of type float.
Add a configuration variable for the price range minimum and maximum.
Write a range query using the range keyword with gte and lte for the price field.
Print the final query JSON.
💡 Why This Matters
🌍 Real World
Range queries are used in search engines to filter results by numbers like price, date, or ratings.
💼 Career
Knowing how to write range queries is important for roles involving search, data filtering, and Elasticsearch administration.
Progress0 / 4 steps
1
Create index mapping with price field
Create a variable called index_mapping and assign it a JSON object with a mappings key. Inside mappings, add properties with a price field of type float.
Elasticsearch
Need a hint?

Use a dictionary with keys mappings and properties. Set price type to float.

2
Set price range variables
Create two variables called min_price and max_price and set them to 50 and 150 respectively.
Elasticsearch
Need a hint?

Assign 50 to min_price and 150 to max_price.

3
Create the range query
Create a variable called range_query and assign it a JSON object with a query key. Inside query, use range on the price field with gte set to min_price and lte set to max_price.
Elasticsearch
Need a hint?

Use the range keyword inside query with gte and lte set to the variables.

4
Print the range query
Write a print statement to display the range_query variable.
Elasticsearch
Need a hint?

Use print(range_query) to show the query.