Stats Aggregation
The stats aggregation provides a summary of statistics, including count, sum, min, max, and average. Let’s get the stats for the price field.
Query:
GET /products/_search
{
"size": 0,
"aggs": {
"price_stats": {
"stats": {
"field": "price"
}
}
}
}
Output
{
"aggregations": {
"price_stats": {
"count": 10,
"min": 100.0,
"max": 1000.0,
"avg": 550.0,
"sum": 5500.0
}
}
}
In this example, we get a summary of statistics for the price field.
Metric Aggregation in Elasticsearch
Elasticsearch is a powerful tool not just for search but also for performing complex data analytics. Metric aggregations are a crucial aspect of this capability, allowing users to compute metrics like averages, sums, and more on numeric fields within their data.
This guide will delve into metric aggregations in Elasticsearch, explaining what they are, how they work, and providing detailed examples to illustrate their use.