Average Aggregation
The average aggregation computes the average value of a numeric field. Let’s calculate the average price of products in our index.
Query:
GET /products/_search
{
"size": 0,
"aggs": {
"avg_price": {
"avg": {
"field": "price"
}
}
}
}
Output:
{
"aggregations": {
"avg_price": {
"value": 550.0
}
}
}
In this example, the average price of products is $550.0.
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.