@Experimental public final class CollectReducer extends Reducer
REDUCE COLLECT, which gathers per-document projections within a
GROUPBY group, optionally sorted and bounded.
The grammar implemented by this reducer is:
REDUCE COLLECT <narg>
FIELDS ( * | <num_fields> <field_1> [<field_2> ...] )
[SORTBY <narg> <@field> [ASC|DESC] [<@field> [ASC|DESC] ...]]
[LIMIT <offset> <count>]
[AS <alias>]
SEARCH_QUERY_BAD `COLLECT` is unavailable when `ENABLE_UNSTABLE_FEATURES` is off.
jedis.configSet("search-enable-unstable-features", "yes");
The flag can also be set permanently in redis.conf or via the matching module-load
argument.
{
@code
AggregationBuilder agg = new AggregationBuilder().loadAll().groupBy("@color",
Reducers.collect().fieldsAll().sortBy(SortedField.desc("@sweetness")).limit(0, 2)
.as("top_fruits"));
}
The reducer is marked Experimental because both the underlying Redis Search feature and
this Java surface are subject to change while the server-side rollout is in progress.Reducers.collect()| Modifier and Type | Method and Description |
|---|---|
CollectReducer |
fields(java.lang.String... fields)
Project the named fields for every document in the group.
|
CollectReducer |
fieldsAll()
Project every field available in the current input row (
FIELDS *). |
protected java.util.List<java.lang.Object> |
getOwnArgs() |
CollectReducer |
limit(int count)
Bound the output per group to the first
count entries (offset 0). |
CollectReducer |
limit(int offset,
int count)
Bound the output per group to
count entries starting at offset. |
CollectReducer |
sortBy(SortedField... fields)
In-group sort by one or more fields.
|
CollectReducer |
sortByAsc(java.lang.String field)
Convenience for
sortBy(SortedField.asc(field)). |
CollectReducer |
sortByDesc(java.lang.String field)
Convenience for
sortBy(SortedField.desc(field)). |
public CollectReducer fields(java.lang.String... fields)
@__key, @__score
or document field names (e.g. @title).
Mutually exclusive with fieldsAll().
public CollectReducer fieldsAll()
FIELDS *).
Per the COLLECT specification, * does not trigger an implicit load — fields must
already be in the pipeline (typically via LOAD * or because they are grouping keys /
reducer aliases).
Mutually exclusive with fields(String...).
public CollectReducer sortBy(SortedField... fields)
public CollectReducer sortByAsc(java.lang.String field)
sortBy(SortedField.asc(field)).public CollectReducer sortByDesc(java.lang.String field)
sortBy(SortedField.desc(field)).public CollectReducer limit(int count)
count entries (offset 0).public CollectReducer limit(int offset, int count)
count entries starting at offset.protected java.util.List<java.lang.Object> getOwnArgs()
getOwnArgs in class ReducerCopyright © 2026. All rights reserved.