Overview

Metrics aggregation is a type of aggregation that calculates metric data such as sum or average. It mainly refers to the mathematical calculations performed across a set of documents, usually based on the values of a numerical field present in the document. There are several types of metrics aggregations available in Elasticsearch, each serving a different purpose, such as:

  • Sum aggregation: It calculates the sum of a numeric field across all documents matching the query.

  • Avg aggregation: It computes the average of a numeric field across the matching documents.

  • Min aggregation: It finds the minimum value of a numeric field among the documents.

  • Max aggregation: It determines the maximum value of a numeric field among the documents.

  • Stats aggregation: It provides a collection of basic statistics about a numeric field, including count, sum, average, min, and max.

  • Extended stats aggregation: It is similar to the stats aggregation, but it includes additional statistical information such as standard deviation and variance.

  • Percentiles aggregation: It computes one or more percentiles (e.g., 25th, 50th, and 75th) for a numeric field.

  • Cardinality aggregation: It estimates the distinct count of values in a numeric or keyword field.

  • Value count aggregation: It counts the number of non-null values in a numeric or keyword field.

  • The top_hits metric aggregator: It keeps track of the most relevant document being aggregated. This aggregator is intended to be used as a sub-aggregator so that the top matching documents can be aggregated per bucket.

Get hands-on with 1200+ tech skills courses.