Skip to main content
Group By stage showing document aggregation by field values
The Group By stage aggregates documents that share the same value for a specified field, creating logical groups. This is useful for organizing results by category, author, date, or any other attribute.
Stage Category: GROUP (Groups documents)Transformation: N documents → G groups (where G = unique field values)

When to Use

When NOT to Use

Parameters

Configuration Examples

Output Schema

Performance

Common Pipeline Patterns

Search + Group by Category

Grouped Results with Aggregations

Time-Based Grouping

Document Sorting Within Groups

Documents within each group are automatically sorted by relevance score (highest first), then limited to max_per_group.

Output Modes

Handling Missing Values

Documents missing the group_by_field value are grouped under a null key.

Error Handling

Group By vs Cluster