From b6bff56a56d03af9b061cc2b180f4e42f8ba3b06 Mon Sep 17 00:00:00 2001 From: Igor Motov Date: Wed, 9 Sep 2020 15:42:12 -0400 Subject: [PATCH] Fix hard_bounds interval handling (#62129) (#62188) The hard bounds were incorrectly scaled for intervals, which was causing incorrect buckets to show up or no buckets at all for interval other than 1. Closes #62126 --- .../elasticsearch/search/aggregations/bucket/HistogramIT.java | 2 +- .../bucket/histogram/NumericHistogramAggregator.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/internalClusterTest/java/org/elasticsearch/search/aggregations/bucket/HistogramIT.java b/server/src/internalClusterTest/java/org/elasticsearch/search/aggregations/bucket/HistogramIT.java index 47003a8bb61..0b06477fb92 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/search/aggregations/bucket/HistogramIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/search/aggregations/bucket/HistogramIT.java @@ -1236,7 +1236,7 @@ public class HistogramIT extends ESIntegTestCase { assertEquals(-0.6, (double) buckets.get(0).getKey(), 0.01d); r = client().prepareSearch("test") - .addAggregation(histogram("histo").field("d").interval(0.1).hardBounds(new DoubleBounds(0.0, 3.0))) + .addAggregation(histogram("histo").field("d").interval(0.1).hardBounds(new DoubleBounds(0.0, 0.3))) .get(); assertSearchResponse(r); diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/NumericHistogramAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/NumericHistogramAggregator.java index 57482b56a0c..bdf734925d9 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/NumericHistogramAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/NumericHistogramAggregator.java @@ -110,7 +110,7 @@ public class NumericHistogramAggregator extends AbstractHistogramAggregator { if (key == previousKey) { continue; } - if (hardBounds == null || hardBounds.contain(key)) { + if (hardBounds == null || hardBounds.contain(key * interval)) { long bucketOrd = bucketOrds.add(owningBucketOrd, Double.doubleToLongBits(key)); if (bucketOrd < 0) { // already seen bucketOrd = -1 - bucketOrd;