0
0
Elasticsearchquery~30 mins

Metric aggregations (avg, sum, min, max) in Elasticsearch - Mini Project: Build & Apply

Choose your learning style9 modes available
Metric Aggregations with Elasticsearch
📖 Scenario: You work for an online store that tracks sales data in Elasticsearch. You want to analyze sales performance by calculating average, total, minimum, and maximum sales amounts.
🎯 Goal: Build an Elasticsearch query that uses metric aggregations to find the average, sum, minimum, and maximum of the sales_amount field.
📋 What You'll Learn
Create an aggregation named average_sales that calculates the average of sales_amount.
Create an aggregation named total_sales that calculates the sum of sales_amount.
Create an aggregation named min_sales that finds the minimum sales_amount.
Create an aggregation named max_sales that finds the maximum sales_amount.
💡 Why This Matters
🌍 Real World
Companies use Elasticsearch metric aggregations to quickly analyze large datasets for business insights like sales performance, customer behavior, and system metrics.
💼 Career
Knowing how to write metric aggregation queries is essential for roles like data analyst, backend developer, and search engineer working with Elasticsearch.
Progress0 / 4 steps
1
Setup the base query structure
Create a JSON object called query with an empty aggs field to hold aggregations.
Elasticsearch
Need a hint?

Start with an empty aggs object inside your query JSON.

2
Add average and sum aggregations
Inside the aggs field, add two aggregations: average_sales using avg on sales_amount, and total_sales using sum on sales_amount.
Elasticsearch
Need a hint?

Use avg and sum aggregation types with the field set to sales_amount.

3
Add minimum and maximum aggregations
Add two more aggregations inside aggs: min_sales using min on sales_amount, and max_sales using max on sales_amount.
Elasticsearch
Need a hint?

Use min and max aggregation types with the field set to sales_amount.

4
Complete the Elasticsearch query
Wrap the aggs object inside a full Elasticsearch query JSON with a size of 0 to only return aggregation results.
Elasticsearch
Need a hint?

Set size to 0 to avoid returning documents and focus on aggregation results.