Nested aggregations
📖 Scenario: You work for a bookstore that wants to analyze sales data stored in Elasticsearch. The data includes books with their genres and sales numbers. You want to find out the total sales per genre and also the average sales per book within each genre.
🎯 Goal: Build an Elasticsearch query using nested aggregations to calculate total sales per genre and average sales per book within each genre.
📋 What You'll Learn
Create a terms aggregation on the
genre field named genresInside
genres, create a sum aggregation on the sales field named total_salesInside
genres, create an average aggregation on the sales field named avg_sales_per_bookOutput the complete JSON query with nested aggregations
💡 Why This Matters
🌍 Real World
Nested aggregations help businesses analyze grouped data with multiple metrics in Elasticsearch, such as sales by category with totals and averages.
💼 Career
Understanding nested aggregations is important for roles like data analyst, backend developer, or Elasticsearch engineer working with search and analytics.
Progress0 / 4 steps