Aggregations
Learn how to summarize or "aggregate" data with cbElasticsearch
Last updated
Was this helpful?
Learn how to summarize or "aggregate" data with cbElasticsearch
Last updated
Was this helpful?
In some cases, you aren't interested in searching documents as you are in retrieving specific information stored within each document. It is for such a purpose that Elasticsearch provides the ability to aggregate, or summarize, index data.
cbElasticsearch's SearchBuilder
provides an aggregation()
method for simple aggregation definitions:
Here's an example of a using SearchBuilder:
This aggregation will retrieve the most recent date value stored in meta.timestamp
.
Use a terms aggregation to return an array of term "buckets", one per value:
To run the query and retrieve aggregations, call searchBuilder.execute()
followed by getAggregations()
. getAggregations()
will return a key/value struct where the key is your provided aggregation name:
For a simple metrics aggregation, you should be able to use the value
or value_as_string
keys of the returned aggregation:
In contrast, bucket aggregations return a buckets
array which can be used as-is or mapped into a separate result entirely:
For a full break down on aggregations, check out the .