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 TypeMethodDescriptionMap<io.fluxzero.common.api.search.Group, Map<String, io.fluxzero.common.api.search.DocumentStats.FieldStats>> Performs aggregation over the given fields for each group.CompletableFuture<Map<io.fluxzero.common.api.search.Group, Map<String, io.fluxzero.common.api.search.DocumentStats.FieldStats>>> 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<io.fluxzero.common.api.search.Group, Long>> Asynchronously counts the number of documents in each group.
-
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.
-
aggregateAsync
CompletableFuture<Map<io.fluxzero.common.api.search.Group, Map<String, io.fluxzero.common.api.search.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
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.
-
countAsync
Asynchronously counts the number of documents in each group.- Returns:
- A future with a map from group identifiers to document counts.
-