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 Details
-
aggregate
Map<io.fluxzero.common.api.search.Group, Map<String, io.fluxzero.common.api.search.DocumentStats.FieldStats>> aggregate(String... fields) Performs aggregation over the given fields for each group.Each
Grouprepresents 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.
-