Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ public long nextValue() throws IOException {
public int docValueCount() {
return dv.docValueCount();
}

@Override
public int nextDoc() throws IOException {
return dv.nextDoc();
}
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1561,4 +1561,47 @@ private void assertMultiSortResponse(int[] expectedDays, BucketOrder... order) {
private ZonedDateTime key(Histogram.Bucket bucket) {
return (ZonedDateTime) bucket.getKey();
}

/**
* See https://github.com/elastic/elasticsearch/issues/39107. Make sure we handle properly different
* timeZones.
*/
public void testDateNanosHistogram() throws Exception {
assertAcked(prepareCreate("nanos").addMapping("_doc", "date", "type=date_nanos").get());
indexRandom(true,
client().prepareIndex("nanos", "_doc", "1").setSource("date", "2000-01-01"));
indexRandom(true,
client().prepareIndex("nanos", "_doc", "2").setSource("date", "2000-01-02"));

//Search interval 24 hours
SearchResponse r = client().prepareSearch("nanos")
.addAggregation(dateHistogram("histo").field("date").
interval(1000 * 60 * 60 * 24).timeZone(ZoneId.of("Europe/Berlin")))
.addDocValueField("date")
.get();
assertSearchResponse(r);

Histogram histogram = r.getAggregations().get("histo");
List<? extends Bucket> buckets = histogram.getBuckets();
assertEquals(2, buckets.size());
assertEquals(946681200000L, ((ZonedDateTime)buckets.get(0).getKey()).toEpochSecond() * 1000);
assertEquals(1, buckets.get(0).getDocCount());
assertEquals(946767600000L, ((ZonedDateTime)buckets.get(1).getKey()).toEpochSecond() * 1000);
assertEquals(1, buckets.get(1).getDocCount());

r = client().prepareSearch("nanos")
.addAggregation(dateHistogram("histo").field("date")
.interval(1000 * 60 * 60 * 24).timeZone(ZoneId.of("UTC")))
.addDocValueField("date")
.get();
assertSearchResponse(r);

histogram = r.getAggregations().get("histo");
buckets = histogram.getBuckets();
assertEquals(2, buckets.size());
assertEquals(946684800000L, ((ZonedDateTime)buckets.get(0).getKey()).toEpochSecond() * 1000);
assertEquals(1, buckets.get(0).getDocCount());
assertEquals(946771200000L, ((ZonedDateTime)buckets.get(1).getKey()).toEpochSecond() * 1000);
assertEquals(1, buckets.get(1).getDocCount());
}
}