Aggregations: Pass extended bounds into HistogramAggregator when creating an unmapped aggregator

This fixes an issue where if the field for the aggregation was unmapped the extended bounds would get dropped and the resulting buckets would not cover the extended bounds requested.

Closes #14735
This commit is contained in:
Colin Goodheart-Smithe 2015-11-13 12:32:28 +00:00
parent 99abb76c78
commit 12bb1b79f6
3 changed files with 34 additions and 3 deletions

View File

@ -173,7 +173,7 @@ public class HistogramAggregator extends BucketsAggregator {
@Override
protected Aggregator createUnmapped(AggregationContext aggregationContext, Aggregator parent, List<PipelineAggregator> pipelineAggregators,
Map<String, Object> metaData) throws IOException {
return new HistogramAggregator(name, factories, rounding, order, keyed, minDocCount, null, null, config.formatter(),
return new HistogramAggregator(name, factories, rounding, order, keyed, minDocCount, extendedBounds, null, config.formatter(),
histogramFactory, aggregationContext, parent, pipelineAggregators, metaData);
}

View File

@ -777,7 +777,6 @@ public class MovAvgIT extends ESIntegTestCase {
.prepareSearch("idx").setTypes("type")
.addAggregation(
histogram("histo").field("test").interval(interval)
.extendedBounds(0L, (long) (interval * (numBuckets - 1)))
.subAggregation(randomMetric("the_metric", VALUE_FIELD))
.subAggregation(movingAvg("movavg_counts")
.window(windowSize)
@ -801,7 +800,6 @@ public class MovAvgIT extends ESIntegTestCase {
.prepareSearch("idx").setTypes("type")
.addAggregation(
histogram("histo").field("test").interval(interval)
.extendedBounds(0L, (long) (interval * (numBuckets - 1)))
.subAggregation(randomMetric("the_metric", VALUE_FIELD))
.subAggregation(movingAvg("movavg_counts")
.window(windowSize)

View File

@ -892,6 +892,39 @@ public class HistogramTests extends ESIntegTestCase {
}
}
public void testPartiallyUnmappedWithExtendedBounds() throws Exception {
SearchResponse response = client()
.prepareSearch("idx", "idx_unmapped")
.addAggregation(
histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(interval)
.extendedBounds((long) -1 * 2 * interval, (long) valueCounts.length * interval)).execute().actionGet();
assertSearchResponse(response);
Histogram histo = response.getAggregations().get("histo");
assertThat(histo, notNullValue());
assertThat(histo.getName(), equalTo("histo"));
List<? extends Bucket> buckets = histo.getBuckets();
assertThat(buckets.size(), equalTo(numValueBuckets + 3));
Histogram.Bucket bucket = buckets.get(0);
assertThat(bucket, notNullValue());
assertThat(((Number) bucket.getKey()).longValue(), equalTo((long) -1 * 2 * interval));
assertThat(bucket.getDocCount(), equalTo(0l));
bucket = buckets.get(1);
assertThat(bucket, notNullValue());
assertThat(((Number) bucket.getKey()).longValue(), equalTo((long) -1 * interval));
assertThat(bucket.getDocCount(), equalTo(0l));
for (int i = 2; i < numValueBuckets + 2; ++i) {
bucket = buckets.get(i);
assertThat(bucket, notNullValue());
assertThat(((Number) bucket.getKey()).longValue(), equalTo((long) (i - 2) * interval));
assertThat(bucket.getDocCount(), equalTo(valueCounts[i - 2]));
}
}
public void testEmptyAggregation() throws Exception {
SearchResponse searchResponse = client().prepareSearch("empty_bucket_idx")
.setQuery(matchAllQuery())