Skip to main content

Max Aggregation

The Max aggregation is a single-value metrics aggregation that keeps track and returns the maximum value among the numeric values extracted from the aggregated documents.

In order to use the Max aggregation import the following:

import zio.elasticsearch.aggregation.MaxAggregation
import zio.elasticsearch.ElasticAggregation.maxAggregation

You can create a Max aggregation using the maxAggregation method this way:

val aggregation: MaxAggregation = maxAggregation(name = "maxAggregation", field = "intField")

You can create a type-safe Max aggregation using the maxAggregation method this way:

// Document.intField must be number value, because of Max aggregation
val aggregation: MaxAggregation = maxAggregation(name = "maxAggregation", field = Document.intField)

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

val aggregationWithMissing: MaxAggregation = maxAggregation(name = "maxAggregation", field = Document.intField).missing(10.0)

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

val multipleAggregations: MultipleAggregations = maxAggregation(name = "maxAggregation1", field = Document.intField).withAgg(maxAggregation(name = "maxAggregation2", field = Document.doubleField))

You can find more information about Max aggregation here.