Sampler

Sampler aggregation

/ Sampler, / Aggregation

Sampler aggregation #

A single-bucket aggregation that keeps only a sample of the matching documents before running its sub-aggregations — used to cut aggregation cost on very large result sets. If a terms aggregation over millions of documents is too slow or too memory-hungry, sampling trades exact counts for an order-of-magnitude answer at a fraction of the cost.

How it works #

The sampler keeps the first shard_size matching documents (default 100) and discards the rest; its sub-aggregations then run over that sample only. The result is a single bucket keyed sample, carrying the sample’s doc_count and the sub-aggregation results:

...