Skip to content
Merged
Changes from all 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 @@ -107,7 +107,7 @@ class DateHistogramAggregator extends BucketsAggregator implements SizedBucketAg
private boolean starTreeDateRoundingRequired = true;

private final FilterRewriteOptimizationContext filterRewriteOptimizationContext;
public final String STARTREE_TIMESTAMP_FIELD = "@timestamp";
public final String fieldName;

DateHistogramAggregator(
String name,
Expand Down Expand Up @@ -172,6 +172,9 @@ protected Function<Long, Long> bucketOrdProducer() {
}
};
filterRewriteOptimizationContext = new FilterRewriteOptimizationContext(bridge, parent, subAggregators.length, context);
this.fieldName = (valuesSource instanceof ValuesSource.Numeric.FieldData)
? ((ValuesSource.Numeric.FieldData) valuesSource).getIndexFieldName()
: null;
this.starTreeDateDimension = (context.getQueryShardContext().getStarTreeQueryContext() != null)
? fetchStarTreeCalendarUnit()
: null;
Expand Down Expand Up @@ -244,13 +247,13 @@ private String fetchStarTreeCalendarUnit() {
.next();
DateDimension starTreeDateDimension = (DateDimension) compositeMappedFieldType.getDimensions()
.stream()
.filter(dim -> dim.getField().equals(STARTREE_TIMESTAMP_FIELD))
.filter(dim -> dim.getField().equals(fieldName))
.findFirst() // Get the first matching time dimension
.orElseThrow(() -> new AssertionError(String.format(Locale.ROOT, "Date dimension '%s' not found", STARTREE_TIMESTAMP_FIELD)));
.orElseThrow(() -> new AssertionError(String.format(Locale.ROOT, "Date dimension '%s' not found", fieldName)));

DateTimeUnitAdapter dateTimeUnitRounding = new DateTimeUnitAdapter(this.rounding.unit());
DateTimeUnitRounding rounding = starTreeDateDimension.findClosestValidInterval(dateTimeUnitRounding);
String dimensionName = STARTREE_TIMESTAMP_FIELD + "_" + rounding.shortName();
String dimensionName = fieldName + "_" + rounding.shortName();
if (rounding.shortName().equals(this.rounding.unit().shortName())) {
this.starTreeDateRoundingRequired = false;
}
Expand Down
Loading