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
Modifier and TypeMethodDescriptionPerforms aggregation over the given fields for each group.aggregateAsync(String... fields) Asynchronously performs aggregation over the given fields for each group.count()Counts the number of documents in each group.default CompletableFuture<Map<Group, Long>> Asynchronously counts the number of documents in each group.
-
Method Details
-
aggregate
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.
-
aggregateAsync
CompletableFuture<Map<Group, Map<String, DocumentStats.FieldStats>>> aggregateAsync(String... fields) Asynchronously performs aggregation over the given fields for each group.This is the asynchronous counterpart of
aggregate(String...). The returned future completes with the same grouped statistics map as the synchronous method.- Parameters:
fields- The fields to aggregate within each group.- Returns:
- A future with a map from group identifiers to aggregated statistics per field.
-
count
-
countAsync
Asynchronously counts the number of documents in each group.- Returns:
- A future with a map from group identifiers to document counts.
-