Compute metrics (sum, avg, min, max) and group data with terms and date_histogram bucket aggregations.
Aggregations
# Metric aggregations
GET /orders/_search
{
"size": 0,
"aggs": {
"total_revenue": { "sum": { "field": "amount" } },
"avg_order": { "avg": { "field": "amount" } },
"min_order": { "min": { "field": "amount" } },
"max_order": { "max": { "field": "amount" } },
"order_count": { "value_count": { "field": "id" } }
}
}
# Bucket aggregation — group by field
GET /posts/_search
{
"size": 0,
"aggs": {
"by_author": {
"terms": { "field": "author", "size": 10 },
"aggs": {
"avg_price": { "avg": { "field": "price" } }
}
}
}
}
# Date histogram
"aggs": { "by_month": { "date_histogram": {
"field": "created_at", "calendar_interval": "month"
}}}