Diversified sampler aggregation
/ Diversified_sampler, / AggregationDiversified sampler aggregation #
Like
sampler, but the sample is diversified by a field
— up to one (or few) documents per value — so rare categories survive
the sampling. A plain sampler can be flooded by the most common value
(every sampled type being t-shirt); the diversified variant
guarantees representation for every distinct value first.
How it works #
The sampler walks the matching documents in two passes. First it caps
each distinct value of the diversify field at max_docs_per_value
(default 1) — extra documents with an already-full value are dropped.
Documents missing the diversify field share one common group. The
survivors are then sorted and truncated to the overall shard_size
(default 100).