Nested aggregation
/ Nested, / Reverse_nested, / AggregationNested aggregation #
A single-bucket aggregation that scopes its sub-aggregations to a
nested object path. Nested field values are addressable as dotted
columns, so sub-aggregations read variants.color style fields
directly — counting per array element where it matters, not per parent
document.
reverse_nested (only valid inside a nested aggregation) jumps back
out to the parent-document scope.
How it works #
The engine returns a single bucket shaped
{ "doc_count": <parents>, …sub-aggs }. Sub-aggregations run over the
parent documents, but the nested path’s values live in multivalue
dotted columns, so a terms on variants.color buckets every array
ELEMENT: over the 30 teaching products with 60 variant elements,
black / white / blue each collect 20. One exception is
top_hits, which is element-level here: each
hit is one stored element carrying _nested: {field, offset}
identity, sorted per the requested sort.