Interface GroupSearch
- All Known Implementing Classes:
DefaultDocumentStore.DefaultSearch.DefaultGroupSearch
This interface is typically obtained from a Search
instance via Search.groupBy(String...)
.
It allows aggregations to be performed within groups defined by one or more field values.
Each unique combination of the specified group fields defines a Group
, and aggregate results
are computed separately for each group.
For example, if grouping by "country"
and aggregating "revenue"
,
the result will contain one entry per country with the aggregated revenue statistics per group.
Usage Example
Map<Group, Map<String, FieldStats>> revenueByCountry = search.groupBy("country").aggregate("revenue");
- See Also:
-
Method Summary
-
Method Details
-
aggregate
Performs aggregation over the given fields for each group.Each
Group
represents a unique combination of field values for the group-by fields. The returned map provides aggregate statistics (such as count, min, max, average, etc.) for each of the specified fields within each group.- Parameters:
fields
- The fields to aggregate within each group.- Returns:
- A map from group identifiers to aggregated statistics per field.
-
count
Counts the number of documents in each group.This is a shorthand for aggregating with default count statistics and extracting the count for the first aggregated field in each group.
- Returns:
- A map from group identifiers to document counts.
-