public static class AggregateArgs.Reducer extends Object
Reducers handle group entries in a GROUPBY operation, performing aggregate operations like counting, summing, averaging, or finding min/max values. Each reducer can have an optional alias using the AS keyword.
{
@code
// Count items in each group
Reducer count = Reducer.count().as("item_count");
// Sum numeric values
Reducer totalSales = Reducer.sum("@sales").as("total_sales");
// Calculate average
Reducer avgPrice = Reducer.avg("@price").as("average_price");
// Find extremes
Reducer maxScore = Reducer.max("@score").as("highest_score");
Reducer minPrice = Reducer.min("@price").as("lowest_price");
// Count distinct values
Reducer uniqueUsers = Reducer.countDistinct("@user_id").as("unique_users");
}
If no alias is provided using as(), the resulting field name will be the function name combined with the field
name (e.g., "count_distinct(@user_id)").
| Constructor and Description |
|---|
Reducer(String function,
List<String> args) |
| Modifier and Type | Method and Description |
|---|---|
AggregateArgs.Reducer |
as(String alias) |
static AggregateArgs.Reducer |
avg(String field)
Static factory method to create an AVG reducer.
|
void |
build(CommandArgs<?,?> args) |
static AggregateArgs.CollectReducer |
collect()
Static factory method to create a
COLLECT reducer. |
static AggregateArgs.Reducer |
count()
Static factory method to create a COUNT reducer.
|
static AggregateArgs.Reducer |
countDistinct(String field)
Static factory method to create a COUNT_DISTINCT reducer.
|
static AggregateArgs.Reducer |
max(String field)
Static factory method to create a MAX reducer.
|
static AggregateArgs.Reducer |
min(String field)
Static factory method to create a MIN reducer.
|
static AggregateArgs.Reducer |
sum(String field)
Static factory method to create a SUM reducer.
|
public AggregateArgs.Reducer as(String alias)
public static AggregateArgs.Reducer count()
public static AggregateArgs.Reducer sum(String field)
field - the field to sumpublic static AggregateArgs.Reducer avg(String field)
field - the field to averagepublic static AggregateArgs.Reducer min(String field)
field - the field to find minimumpublic static AggregateArgs.Reducer max(String field)
field - the field to find maximumpublic static AggregateArgs.Reducer countDistinct(String field)
field - the field to count distinct values@Experimental public static AggregateArgs.CollectReducer collect()
COLLECT reducer.
COLLECT gathers per-document projections within a GROUPBY group and returns them as an array of
per-entry maps under the reducer alias, optionally sorted and bounded. Configure the projected fields via
fields(...) or fieldsAll(), then
optionally chain sortBy(...) and
limit(...) before calling as(...).
The collected column is a FieldValue of kind
FieldValue.Kind.ARRAY with one element per collected entry; read the entries via
asList() and each entry via
asMap(), which normalizes the protocol-specific entry shape.
Experimental. Both the underlying Redis Search feature and this API may change. COLLECT is
gated behind search-enable-unstable-features; enable it on the server (for example via
CONFIG SET search-enable-unstable-features yes) before issuing aggregations that use this reducer, otherwise
the server replies with an error.
AggregateArgs.CollectReducer instanceAggregateArgs.CollectReducerpublic void build(CommandArgs<?,?> args)
Copyright © 2026 lettuce.io. All rights reserved.