Class ReplaceSampledStatsByExactStats


If the original aggregate wrapped by the sampled aggregate can be pushed down to Lucene (so that it will execute exact and fast), sampling should be skipped and the original aggregate should be executed.

In that case, this rule replaces the sampled aggregate by a regular aggregate and replicates the exact intermediate values to all bucket intermediates. The plan:

 FROM data | EVAL bucket_id=... | SAMPLED_STATS original_aggs, bucket_aggs
 
is (loosely) transformed into:
 FROM data | ES_STATS_QUERY original_aggs | EVAL bucket_aggs=original_aggs
 
Replicating the exact value to all buckets makes exact data appear as zero-variance sampled data, so confidence intervals remain correct in mixed exact/sampled scenarios (where some nodes push down exact stats and others use sampling).