Field collapsing

Field collapsing #

Collapse the result list so each distinct value of a field appears at most once — “best product per merchant”, “best article per author” — without a terms aggregation, keeping full hit semantics (scores, source, highlight).

POST /my-collection/_search

Example #

One best-selling hit per product type (the dataset has four: hat, t-shirt, mug, sticker); the plain match-all total stays 120 — collapse deduplicates the RESULT list, not the count.

Each returned hit is the highest-scoring document for its collapse field value, and carries an other_from_merchant array with the next best documents sharing that value.

Parameters #

  • field
    (Required, string) The field to collapse on. Keyword-like fields with doc values give the cheapest collapse.
  • inner_hits
    (Optional, object) Also return the top runner-up documents of each group:
    • name (Required, string) Key under which the inner hits appear.
    • size (Optional, integer, default: 3) Runner-ups per group.
    • sort (Optional) Sort clause for the runner-ups.
    • collapse (Optional) Nested collapse for a second-level grouping.
  • max_concurrent_group_searches
    (Optional, integer) Bound on parallel group searches for inner hits.

Notes #

  • Collapse runs after scoring, so the top hit per group is the best match, not the newest document.
  • Pagination applies to collapsed groups, not raw documents.
  • For full per-group analytics (counts, aggregations over group members) use a terms aggregation with sub-aggs instead; collapse is for result-list shape.
Calendar September 27, 2026
Edit Edit this page