@@ -107,7 +107,7 @@ class DateHistogramAggregator extends BucketsAggregator implements SizedBucketAg
107
107
private boolean starTreeDateRoundingRequired = true ;
108
108
109
109
private final FilterRewriteOptimizationContext filterRewriteOptimizationContext ;
110
- public final String STARTREE_TIMESTAMP_FIELD = "@timestamp" ;
110
+ public final String fieldName ;
111
111
112
112
DateHistogramAggregator (
113
113
String name ,
@@ -172,6 +172,9 @@ protected Function<Long, Long> bucketOrdProducer() {
172
172
}
173
173
};
174
174
filterRewriteOptimizationContext = new FilterRewriteOptimizationContext (bridge , parent , subAggregators .length , context );
175
+ this .fieldName = (valuesSource instanceof ValuesSource .Numeric .FieldData )
176
+ ? ((ValuesSource .Numeric .FieldData ) valuesSource ).getIndexFieldName ()
177
+ : null ;
175
178
this .starTreeDateDimension = (context .getQueryShardContext ().getStarTreeQueryContext () != null )
176
179
? fetchStarTreeCalendarUnit ()
177
180
: null ;
@@ -244,13 +247,13 @@ private String fetchStarTreeCalendarUnit() {
244
247
.next ();
245
248
DateDimension starTreeDateDimension = (DateDimension ) compositeMappedFieldType .getDimensions ()
246
249
.stream ()
247
- .filter (dim -> dim .getField ().equals (STARTREE_TIMESTAMP_FIELD ))
250
+ .filter (dim -> dim .getField ().equals (fieldName ))
248
251
.findFirst () // Get the first matching time dimension
249
- .orElseThrow (() -> new AssertionError (String .format (Locale .ROOT , "Date dimension '%s' not found" , STARTREE_TIMESTAMP_FIELD )));
252
+ .orElseThrow (() -> new AssertionError (String .format (Locale .ROOT , "Date dimension '%s' not found" , fieldName )));
250
253
251
254
DateTimeUnitAdapter dateTimeUnitRounding = new DateTimeUnitAdapter (this .rounding .unit ());
252
255
DateTimeUnitRounding rounding = starTreeDateDimension .findClosestValidInterval (dateTimeUnitRounding );
253
- String dimensionName = STARTREE_TIMESTAMP_FIELD + "_" + rounding .shortName ();
256
+ String dimensionName = fieldName + "_" + rounding .shortName ();
254
257
if (rounding .shortName ().equals (this .rounding .unit ().shortName ())) {
255
258
this .starTreeDateRoundingRequired = false ;
256
259
}
0 commit comments