From f658a8d137fd40d110135ff8c6ade973d45f8ced Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Thu, 18 May 2017 11:07:48 +0200 Subject: DateHistogram: Fix 'extended_bounds' with 'offset' (#23789) This fixes a bug in the 'date_histogram' aggregation that can happen when using 'extended_bounds' together with some 'offset' parameter. Offsets should be applied after rounding the extended bounds and also be applied when adding empty buckets during the reduce phase in InternalDateHistogram. Closes #23776 --- .../aggregations/bucket/DateHistogramIT.java | 56 +++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) (limited to 'core/src/test/java/org/elasticsearch/search/aggregations/bucket') diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramIT.java index 283f964b68..db5a0a1cd8 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramIT.java @@ -1162,7 +1162,61 @@ public class DateHistogramIT extends ESIntegTestCase { assertThat(bucket.getDocCount(), equalTo(0L)); } } - internalCluster().wipeIndices("test12278"); + internalCluster().wipeIndices(index); + } + + /** + * Test date histogram aggregation with day interval, offset and + * extended bounds (see https://github.com/elastic/elasticsearch/issues/23776) + */ + public void testSingleValueFieldWithExtendedBoundsOffset() throws Exception { + String index = "test23776"; + prepareCreate(index) + .setSettings(Settings.builder().put(indexSettings()).put("index.number_of_shards", 1).put("index.number_of_replicas", 0)) + .execute().actionGet(); + + List builders = new ArrayList<>(); + builders.add(indexDoc(index, DateTime.parse("2016-01-03T08:00:00.000Z"), 1)); + builders.add(indexDoc(index, DateTime.parse("2016-01-03T08:00:00.000Z"), 2)); + builders.add(indexDoc(index, DateTime.parse("2016-01-06T08:00:00.000Z"), 3)); + builders.add(indexDoc(index, DateTime.parse("2016-01-06T08:00:00.000Z"), 4)); + indexRandom(true, builders); + ensureSearchable(index); + + SearchResponse response = null; + // retrieve those docs with the same time zone and extended bounds + response = client() + .prepareSearch(index) + .addAggregation( + dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.days(1)).offset("+6h").minDocCount(0) + .extendedBounds(new ExtendedBounds("2016-01-01T06:00:00Z", "2016-01-08T08:00:00Z")) + ).execute().actionGet(); + assertSearchResponse(response); + + Histogram histo = response.getAggregations().get("histo"); + assertThat(histo, notNullValue()); + assertThat(histo.getName(), equalTo("histo")); + List buckets = histo.getBuckets(); + assertThat(buckets.size(), equalTo(8)); + + assertEquals("2016-01-01T06:00:00.000Z", buckets.get(0).getKeyAsString()); + assertEquals(0, buckets.get(0).getDocCount()); + assertEquals("2016-01-02T06:00:00.000Z", buckets.get(1).getKeyAsString()); + assertEquals(0, buckets.get(1).getDocCount()); + assertEquals("2016-01-03T06:00:00.000Z", buckets.get(2).getKeyAsString()); + assertEquals(2, buckets.get(2).getDocCount()); + assertEquals("2016-01-04T06:00:00.000Z", buckets.get(3).getKeyAsString()); + assertEquals(0, buckets.get(3).getDocCount()); + assertEquals("2016-01-05T06:00:00.000Z", buckets.get(4).getKeyAsString()); + assertEquals(0, buckets.get(4).getDocCount()); + assertEquals("2016-01-06T06:00:00.000Z", buckets.get(5).getKeyAsString()); + assertEquals(2, buckets.get(5).getDocCount()); + assertEquals("2016-01-07T06:00:00.000Z", buckets.get(6).getKeyAsString()); + assertEquals(0, buckets.get(6).getDocCount()); + assertEquals("2016-01-08T06:00:00.000Z", buckets.get(7).getKeyAsString()); + assertEquals(0, buckets.get(7).getDocCount()); + + internalCluster().wipeIndices(index); } public void testSingleValueWithMultipleDateFormatsFromMapping() throws Exception { -- cgit v1.2.3 From 55af1f7a2b503d7997b476c34f952bd9fce6eeb5 Mon Sep 17 00:00:00 2001 From: Tanguy Leroux Date: Fri, 19 May 2017 13:12:01 +0200 Subject: [Test] Remove leftover in InternalRangeTests --- .../search/aggregations/bucket/range/InternalRangeTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/src/test/java/org/elasticsearch/search/aggregations/bucket') diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/range/InternalRangeTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/range/InternalRangeTests.java index 9264028d07..a371d94529 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/range/InternalRangeTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/range/InternalRangeTests.java @@ -43,7 +43,7 @@ public class InternalRangeTests extends InternalRangeTestCase { format = randomNumericDocValueFormat(); final int interval = randomFrom(1, 5, 10, 25, 50, 100); - final int numRanges = 1;//randomIntBetween(1, 10); + final int numRanges = randomIntBetween(1, 10); List> listOfRanges = new ArrayList<>(numRanges); for (int i = 0; i < numRanges; i++) { -- cgit v1.2.3