|
|
@@ -67,9 +67,10 @@ class DateRangeHistogramAggregator extends BucketsAggregator {
|
|
|
private final ExtendedBounds extendedBounds;
|
|
|
|
|
|
private final LongHash bucketOrds;
|
|
|
+ private long offset;
|
|
|
|
|
|
DateRangeHistogramAggregator(String name, AggregatorFactories factories, Rounding rounding, Rounding shardRounding,
|
|
|
- BucketOrder order, boolean keyed,
|
|
|
+ long offset, BucketOrder order, boolean keyed,
|
|
|
long minDocCount, @Nullable ExtendedBounds extendedBounds, @Nullable ValuesSource.Range valuesSource,
|
|
|
DocValueFormat formatter, SearchContext aggregationContext,
|
|
|
Aggregator parent, List<PipelineAggregator> pipelineAggregators,
|
|
|
@@ -78,6 +79,7 @@ class DateRangeHistogramAggregator extends BucketsAggregator {
|
|
|
super(name, factories, aggregationContext, parent, pipelineAggregators, metaData);
|
|
|
this.rounding = rounding;
|
|
|
this.shardRounding = shardRounding;
|
|
|
+ this.offset = offset;
|
|
|
this.order = InternalOrder.validate(order, this);
|
|
|
this.keyed = keyed;
|
|
|
this.minDocCount = minDocCount;
|
|
|
@@ -124,8 +126,8 @@ class DateRangeHistogramAggregator extends BucketsAggregator {
|
|
|
// The encoding should ensure that this assert is always true.
|
|
|
assert from >= previousFrom : "Start of range not >= previous start";
|
|
|
final Long to = (Long) range.getTo();
|
|
|
- final long startKey = shardRounding.round(from);
|
|
|
- final long endKey = shardRounding.round(to);
|
|
|
+ final long startKey = offsetAwareRounding(shardRounding, from, offset);
|
|
|
+ final long endKey = offsetAwareRounding(shardRounding, to, offset);
|
|
|
for (long key = startKey > previousKey ? startKey : previousKey; key <= endKey;
|
|
|
key = shardRounding.nextRoundingValue(key)) {
|
|
|
if (key == previousKey) {
|
|
|
@@ -151,6 +153,10 @@ class DateRangeHistogramAggregator extends BucketsAggregator {
|
|
|
};
|
|
|
}
|
|
|
|
|
|
+ private long offsetAwareRounding(Rounding rounding, long value, long offset) {
|
|
|
+ return rounding.round(value - offset) + offset;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public InternalAggregation buildAggregation(long owningBucketOrdinal) throws IOException {
|
|
|
assert owningBucketOrdinal == 0;
|
|
|
@@ -169,7 +175,7 @@ class DateRangeHistogramAggregator extends BucketsAggregator {
|
|
|
InternalDateHistogram.EmptyBucketInfo emptyBucketInfo = minDocCount == 0
|
|
|
? new InternalDateHistogram.EmptyBucketInfo(rounding, buildEmptySubAggregations(), extendedBounds)
|
|
|
: null;
|
|
|
- return new InternalDateHistogram(name, buckets, order, minDocCount, rounding.offset(), emptyBucketInfo, formatter, keyed,
|
|
|
+ return new InternalDateHistogram(name, buckets, order, minDocCount, offset, emptyBucketInfo, formatter, keyed,
|
|
|
pipelineAggregators(), metaData());
|
|
|
}
|
|
|
|
|
|
@@ -178,8 +184,8 @@ class DateRangeHistogramAggregator extends BucketsAggregator {
|
|
|
InternalDateHistogram.EmptyBucketInfo emptyBucketInfo = minDocCount == 0
|
|
|
? new InternalDateHistogram.EmptyBucketInfo(rounding, buildEmptySubAggregations(), extendedBounds)
|
|
|
: null;
|
|
|
- return new InternalDateHistogram(name, Collections.emptyList(), order, minDocCount, rounding.offset(), emptyBucketInfo, formatter,
|
|
|
- keyed, pipelineAggregators(), metaData());
|
|
|
+ return new InternalDateHistogram(name, Collections.emptyList(), order, minDocCount, offset, emptyBucketInfo, formatter, keyed,
|
|
|
+ pipelineAggregators(), metaData());
|
|
|
}
|
|
|
|
|
|
@Override
|