Skip to main content
Unwind stage showing array decomposition into separate documents
The Unwind stage decomposes array fields into separate documents, producing one output document per array element. This is the retriever pipeline equivalent of MongoDB’s $unwind, Snowflake’s LATERAL FLATTEN, and Spark’s explode().
Stage Category: APPLY (Expands documents)Transformation: N documents → M documents (where M ≥ N, one per array element)

When to Use

When NOT to Use

Parameters

Configuration Examples

How It Works

  1. For each input document, extracts the array value at the specified field path
  2. If the value is an array with K elements, produces K output documents
  3. Each output document preserves all original fields, with the array field replaced by a single element
  4. Documents with null/empty arrays are either dropped or preserved based on preserve_null_and_empty
  5. Non-array values are passed through unchanged
Use include_array_index when you need to reconstruct the original order later, such as when reassembling video segments after per-segment scoring.

Performance

Common Pipeline Patterns

Per-Tag Scoring

Segment-Level Retrieval

Error Handling

  • JSON Transform - Restructure document fields without expansion
  • Group By - Inverse operation: group documents by field value
  • Deduplicate - Remove duplicates after expansion