AI Hints
Home›Elasticsearch Tutorial›Metrics and Statistics
Elasticsearch · Lesson 70 of 120

Metric Aggregations

Sum, avg, min, max.

⏱ 2 min read▶ Video at 1:06:24🎓 Free
Watch this lesson in the Elasticsearch courseWatch on YouTube ↗Full Elasticsearch course

Trailhead's two thousand orders from twenty twenty six are now in an orders index. The boss asks, what's our total revenue, and our biggest single order?

  • 2,000 orders
  • Total revenue?
  • Biggest order?

Revenue numbers

We ask for four metrics at once. Sum of total, average total, the max, and the min. Run it. Total revenue, the average order, and the biggest and smallest orders.

Dev Tools Consoletext
GET orders/_search?filter_path=aggregations
{
  "size": 0,
  "aggs": {
    "revenue":  { "sum": { "field": "total" } },
    "average":  { "avg": { "field": "total" } },
    "biggest":  { "max": { "field": "total" } },
    "smallest": { "min": { "field": "total" } }
  }
}
Output
{
  "aggregations": {
    "revenue": {"value": 480787.03},
    "average": {"value": 240.3935},
    "biggest": {"value": 1616.97},
    "smallest": {"value": 20.99}
  }
}
Also uses _load
orders

Metric aggregations

Sum, avg, min and max are the basics. Value count counts values. Every metric works on numbers and dates. And you can give each aggregation any name you like.

keyvalue
sum, avgtotals and means
min, maxextremes
value_counthow many values
Namesyour choice

Summary

Metric aggregations like sum, avg, min and max turn thousands of documents into a few numbers. Next, stats and percentiles.

Key takeaways
  • sum
  • avg
  • min / max
Next up: stats and Percentiles — the whole picture