Combined aggregation

Combined aggregation in Elasticsearch refers to the practice of using multiple aggregation types together within a single aggregation request. It allows us to perform a hierarchical analysis of our data by applying both bucket and metrics aggregations simultaneously.

Bucket aggregations group documents into buckets based on certain criteria, such as field values, date ranges, or terms. They create a structured view of the data, organizing it into meaningful clusters or categories.

On the other hand, metrics aggregations calculate various metrics (e.g., sum, average, min, and max) within each bucket or across the entire dataset. They provide quantitative insights and statistical measures that help us understand the characteristics of the data within each bucket.

This amalgamation grants a range of benefits. It facilitates a structured view by organizing data into meaningful clusters, facilitating coherent analysis. For instance, let’s imagine we are trying to understand sales data. Using bucket aggregation, we can group products into categories, which helps us see how different types of products contribute to overall sales. Then, by using the stats metrics aggregation, we can dig even deeper and figure out things like the average sales for each specific product category. This combination of techniques helps us develop a clear view of both the big picture and the smaller details in our sales analysis.

Let’s consider a real-world scenario to better grasp the concept of combined aggregation by visualizing a collection of customer orders from an online store. Each order contains details like the product purchased, its corresponding category, and the total cost. Here are four instances of such products to help illustrate the idea:

Get hands-on with 1200+ tech skills courses.