aggs

fun aggs(vararg aggregations: Pair<String, Aggregation<*>>): T
fun aggs(aggregations: Map<String, Aggregation<*>>): T

Adds aggregations to the existing query aggregations.

Parameters

aggregations

pairs of the aggregation name and the aggregation itself. The aggregation name can be used to retrieve an aggregation result using SearchQueryResult.aggs method.

See also

Samples

import dev.evo.elasticmagic.SearchQuery
import dev.evo.elasticmagic.aggs.HistogramAgg
import dev.evo.elasticmagic.aggs.TermsAgg
import dev.evo.elasticmagic.doc.Document
import dev.evo.elasticmagic.query.Bool
import dev.evo.elasticmagic.query.FunctionScore
import dev.evo.elasticmagic.query.MatchPhrase
import dev.evo.elasticmagic.query.MultiMatch
import dev.evo.elasticmagic.query.NodeHandle
import dev.evo.elasticmagic.query.QueryExpressionNode
import dev.evo.elasticmagic.query.QueryRescore
import dev.evo.elasticmagic.query.match
import kotlin.random.Random

fun main() { 
   //sampleStart 
   // Calculate a histogram for user rank and for every bucket in the histogram
// count active and non-active users
searchQuery.aggs(
    "rank_hist" to HistogramAgg(
        UserDoc.rank,
        interval = 1.0F,
        aggs = mapOf(
            "is_active" to TermsAgg(UserDoc.isActive)
        )
    )
) 
   //sampleEnd
}

fun aggs(clear: SearchQuery.CLEAR): T

Clears the existing aggregations.