Skip to main content

Percentiles Aggregation

The Percentiles aggregation is a multi-value metrics aggregation that calculates one or more percentiles over numeric values extracted from the aggregated documents.

In order to use the Percentiles aggregation import the following:

import zio.elasticsearch.aggregation.PercentilesAggregation
import zio.elasticsearch.ElasticAggregation.percentilesAggregation

You can create a Percentiles aggregation using the percentilesAggregation method this way:

val aggregation: PercentilesAggregation = percentilesAggregation(name = "percentilesAggregation", field = "intField")

You can create a type-safe Percentiles aggregation using the percentilesAggregation method this way:

// Document.intField must be number value
val aggregation: PercentilesAggregation = percentilesAggregation(name = "percentilesAggregation", field = Document.intField)

If you want to specify the percentiles you want to calculate, you can use percents method:

val aggregationWithPercents: PercentilesAggregation = percentilesAggregation(name = "percentilesAggregation", field = Document.intField).percents(15, 50, 70)

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

val aggregationWithMissing: PercentilesAggregation = percentilesAggregation(name = "percentilesAggregation", field = Document.intField).missing(10.0)

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

val multipleAggregations: MultipleAggregations = percentilesAggregation(name = "percentilesAggregation1", field = Document.intField).withAgg(percentilesAggregation(name = "percentilesAggregation2", field = Document.doubleField))

You can find more information about Percentiles aggregation here.