Stats Statement

Metrics Aggregations

The aggregations in this family compute metrics based on values extracted in one way or another from the documents that are being aggregated.

source 'employee'
 | stats minAge=min(Age),maxAge=max(Age),countAge=count(Age),
    percentilesAge=percentiles(Age),sumAge=sum(Age),cardinalityAge=cardinality(Age)

Metrics Aggregations Over Fields

The clause (query) must appear in matching documents

source 'employee' | search Gender='Male'
 | stats min_age=min(Age),max_age=max(Age) by MaritalStatus

Multiple fields

source 'employee' |  stats min_age=min(Age),max_age=max(Age) by MaritalStatus,Gender

Supported Functions

  • avg: calculates avg
  • min: calculates min
  • max: calculates max
  • count: counts the number of values that are extracted from the aggregated documents
  • percentiles: calculates percentiles
  • sum: calculates sum
  • cardinality: calculates an approximate count of distinct values

Date Histogram Aggregation

A multi-bucket aggregation similar to the histogram except it can only be applied on date values. Date histogram

source 'employee' | search Gender='Male'
 | stats min_age=min(Age),max_age=max(Age) by MaritalStatus

Date histogram aggregation over a field

source 'employee'
 | datehistogram field='DateOfJoining', interval='year' by Gender

Histogram Aggregation

A multi-bucket values source based aggregation that can be applied on numeric values extracted from the documents. It dynamically builds fixed size (a.k.a. interval) buckets over the values. Date histogram

source 'employee' | histogram field='Age', interval='10' by Gender

aggregation over field

source 'employee' | histogram field='Age', interval='10' do max_age=max(Age) by Gender