Cardinality Aggregation
The Cardinality
aggregation is a single-value metrics aggregation that calculates an approximate count of distinct values.
In order to use the Cardinality
aggregation import the following:
import zio.elasticsearch.aggregation.CardinalityAggregation
import zio.elasticsearch.ElasticAggregation.cardinalityAggregation
You can create a Cardinality
aggregation using the cardinalityAggregation
method in the following manner:
val aggregation: CardinalityAggregation = cardinalityAggregation(name = "cardinalityAggregation", field = "intField")
You can create a type-safe Cardinality
aggregation using the cardinalityAggregation
method in the following manner:
val aggregation: CardinalityAggregation = cardinalityAggregation(name = "cardinalityAggregation", field = Document.intField)
If you want to change the missing
, you can use missing
method:
val aggregationWithMissing: CardinalityAggregation = cardinalityAggregation(name = "cardinalityAggregation", field = Document.intField).missing(10.0)
If you want to add aggregation (on the same level), you can use withAgg
method:
val multipleAggregations: MultipleAggregations = cardinalityAggregation(name = "cardinalityAggregation", field = Document.intField).withAgg(maxAggregation(name = "maxAggregation", field = Document.doubleField))
You can find more information about Cardinality
aggregation here.