Skip to main content

Extended stats Aggregation

The Extended stats aggregation is a multi-value metrics aggregation that provides statistical information (count, sum, min, max, average, sum od squares, variance and std deviation of a field) over numeric values extracted from the aggregated documents. The Extended stats aggregation is an extended version of the Stats aggregation.

In order to use the Extended stats aggregation import the following:

import zio.elasticsearch.aggregation.ExtendedStatsAggregation
import zio.elasticsearch.ElasticAggregation.extendedStatsAggregation

You can create a Extended stats aggregation using the extendedStatsAggregation method this way:

val aggregation: ExtendedStatsAggregation = extendedStatsAggregation(name = "extendedStatsAggregation", field = "intField")

You can create a type-safe Extended stats aggregation using the extendedStatsAggregation method this way:

// Document.intField must be number value, because of Stats aggregation
val aggregation: ExtendedStatsAggregation = extendedStatsAggregation(name = "extendedStatsAggregation", field = Document.intField)

If you want to change the missing parameter, you can use missing method:

val aggregationWithMissing: ExtendedStatsAggregation = extendedStatsAggregation(name = "extendedStatsAggregation", field = Document.intField).missing(10.0)

If you want to change the sigma parameter, you can use sigma method:

val aggregationWithSigma: ExtendedStatsAggregation = extendedStatsAggregation(name = "extendedStatsAggregation", field = Document.intField).sigma(3.0)

If you want to add aggregation (on the same level), you can use withAgg method:

val multipleAggregations: MultipleAggregations = extendedStatsAggregation(name = "extendedStatsAggregation1", field = Document.intField).withAgg(extendedStatsAggregation(name = "extendedStatsAggregation2", field = Document.doubleField))

You can find more information about Extended stats aggregation here.