diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalAutoDateHistogram.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalAutoDateHistogram.java index f10318de02e..3be59c0c1f7 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalAutoDateHistogram.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalAutoDateHistogram.java @@ -526,6 +526,9 @@ public final class InternalAutoDateHistogram extends if (buckets.size() > targetBuckets) { for (int interval : roundingInfo.innerIntervals) { int resultingBuckets = buckets.size() / interval; + if (buckets.size() % interval != 0) { + resultingBuckets++; + } if (resultingBuckets <= targetBuckets) { return mergeConsecutiveBuckets(buckets, interval, roundingIdx, roundingInfo, reduceContext); } diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalAutoDateHistogramTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalAutoDateHistogramTests.java index bc4c84282b2..57020901aae 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalAutoDateHistogramTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalAutoDateHistogramTests.java @@ -108,10 +108,7 @@ public class InternalAutoDateHistogramTests extends InternalMultiBucketAggregati assertThat(result, equalTo(2)); } - - @Override - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/39497") - // TODO: When resolving the above AwaitsFix, just delete this override. Method is only overriden to apply the annotation. + public void testReduceRandom() { super.testReduceRandom(); }