public static class AggregateArgs.GroupBy<K,V> extends Object implements AggregateArgs.PipelineOperation<K,V>
Groups the results in the pipeline based on one or more properties. Each group should have at least one reducer function that handles the group entries, either counting them or performing multiple aggregate operations.
{
@code
// Group by category and count items
GroupBy groupBy = GroupBy.of("category").reduce(Reducer.count().as("item_count"));
// Group by multiple fields with multiple reducers
GroupBy complexGroup = GroupBy.of("category", "brand").reduce(Reducer.count().as("count"))
.reduce(Reducer.avg("@price").as("avg_price")).reduce(Reducer.sum("@quantity").as("total_quantity"));
}
Performance Note: Properties used in GROUPBY should be stored as SORTABLE in the index for optimal performance.
| Modifier and Type | Method and Description |
|---|---|
void |
build(CommandArgs<K,V> args)
Build the operation arguments into the command args.
|
static <K,V> AggregateArgs.GroupBy<K,V> |
of(K... properties)
Static factory method to create a GroupBy instance.
|
AggregateArgs.GroupBy<K,V> |
reduce(AggregateArgs.Reducer<K,V> reducer) |
public AggregateArgs.GroupBy<K,V> reduce(AggregateArgs.Reducer<K,V> reducer)
@SafeVarargs public static <K,V> AggregateArgs.GroupBy<K,V> of(K... properties)
K - Key typeV - Value typeproperties - the properties to group bypublic void build(CommandArgs<K,V> args)
AggregateArgs.PipelineOperationbuild in interface AggregateArgs.PipelineOperation<K,V>args - the command args to build intoCopyright © 2025 lettuce.io. All rights reserved.