Skip to content

feat(search): add COLLECT reducer to FT.AGGREGATE#3310

Open
nkaradzhov wants to merge 2 commits into
redis:masterfrom
nkaradzhov:collect-aggregate
Open

feat(search): add COLLECT reducer to FT.AGGREGATE#3310
nkaradzhov wants to merge 2 commits into
redis:masterfrom
nkaradzhov:collect-aggregate

Conversation

@nkaradzhov

@nkaradzhov nkaradzhov commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Support the experimental COLLECT reducer (Redis Search 8.8), which fetches whole documents or projected fields within each GROUPBY group, with optional DISTINCT, in-group SORTBY, and LIMIT.

  • FIELDS '*' emits a bare wildcard token; an explicit list is count-prefixed
  • nargs is computed dynamically via pushVariadicWithLength (unlike the fixed-narg reducers), covering FIELDS/DISTINCT/SORTBY/LIMIT
  • reuses pushSortByProperty for the nested SORTBY clause
  • HYBRID picks up COLLECT automatically (shared parseGroupByReducer)

Description

Describe your pull request here


Checklist

  • Does npm test pass with this change (including linting)?
  • Is the new or changed code fully tested?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?

Note

Low Risk
Additive search client API and command serialization with broad test coverage; no changes to auth, data persistence, or existing reducer behavior.

Overview
Adds client support for the experimental COLLECT GROUPBY reducer on FT.AGGREGATE (Redis Search 8.8+), so callers can return full documents or selected fields per group with optional in-group SORTBY, LIMIT, and AS aliases.

parseGroupByReducer now emits the COLLECT wire format: FIELDS * vs count-prefixed field lists, dynamic nargs via pushVariadicWithLength, and reuse of pushSortByProperty for nested sort clauses. A new CollectReducer type extends the public GroupByReducers union.

Tests cover argument transformation (including real-world-style examples) and an integration case against Redis started with --search-enable-unstable-features, gated to Docker 8.8 via a new GLOBAL.SERVERS.OPEN_UNSTABLE preset.

Reviewed by Cursor Bugbot for commit 8a7ece9. Bugbot is set up for automated code reviews on this repo. Configure here.

@nkaradzhov nkaradzhov requested a review from PavelPashov June 17, 2026 12:35
nkaradzhov and others added 2 commits June 22, 2026 12:30
Support the experimental COLLECT reducer (Redis Search 8.8), which fetches
whole documents or projected fields within each GROUPBY group, with optional
DISTINCT, in-group SORTBY, and LIMIT.

- FIELDS '*' emits a bare wildcard token; an explicit list is count-prefixed
- nargs is computed dynamically via pushVariadicWithLength (unlike the
  fixed-narg reducers), covering FIELDS/DISTINCT/SORTBY/LIMIT
- reuses pushSortByProperty for the nested SORTBY clause
- HYBRID picks up COLLECT automatically (shared parseGroupByReducer)

Tests: arg-serialization specs plus an integration test gated behind a new
OPEN_UNSTABLE server config (--search-enable-unstable-features yes), required
because COLLECT is rejected when unstable features are off.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
COLLECT reducer is only available on RediSearch >= 8.8 (behind
--search-enable-unstable-features). Older matrix servers (7.4/8.2/8.4)
reject it with "No such reducer: COLLECT". Gate the live test with
minimumDockerVersion so it skips on those and runs on 8.8.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Comment on lines +392 to +394
if (reducer.DISTINCT) {
args.push('DISTINCT');
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please check if this is correct, I get the following error:

Error: SEARCH_PARSE_ARGS Bad arguments for COLLECT: DISTINCT: Unknown argument

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out DISTINCT is not yet merged: RediSearch/RediSearch#9982

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 8a7ece9. Configure here.

Comment thread packages/search/lib/commands/AGGREGATE.ts
@PavelPashov PavelPashov self-requested a review June 22, 2026 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants