0
0
Elasticsearchquery~30 mins

Stats and extended stats in Elasticsearch - Mini Project: Build & Apply

Choose your learning style9 modes available
Stats and extended stats
📖 Scenario: You are working with a small dataset of sales amounts in an Elasticsearch index. You want to calculate basic statistics like count, min, max, and average, and then extend it to include sum of squares, variance, and standard deviation.
🎯 Goal: Build Elasticsearch aggregation queries step-by-step to calculate stats and extended_stats on the sales field.
📋 What You'll Learn
Create an aggregation query with stats on the sales field
Add a variable field_name with value sales
Create an aggregation query with extended_stats on the sales field using the variable
Print the final JSON aggregation query
💡 Why This Matters
🌍 Real World
Calculating statistics on sales data helps businesses understand performance, detect trends, and make decisions.
💼 Career
Elasticsearch is widely used for search and analytics. Knowing how to write aggregation queries for stats is valuable for data engineers and backend developers.
Progress0 / 4 steps
1
Create a stats aggregation query
Create a JSON object called stats_query with an aggregation named sales_stats that uses the stats aggregation on the field sales.
Elasticsearch
Need a hint?

Use the stats aggregation inside aggs with the field sales.

2
Add a field name variable
Create a variable called field_name and set it to the string "sales".
Elasticsearch
Need a hint?

Just assign the string "sales" to the variable field_name.

3
Create an extended_stats aggregation using the variable
Create a JSON object called extended_stats_query with an aggregation named sales_extended_stats that uses the extended_stats aggregation on the field stored in the variable field_name.
Elasticsearch
Need a hint?

Use the variable field_name as the value for the field key inside extended_stats.

4
Print the extended_stats query
Write a print statement to display the extended_stats_query JSON object.
Elasticsearch
Need a hint?

Use print(extended_stats_query) to show the final JSON.