@@ -107,7 +107,7 @@ class DateHistogramAggregator extends BucketsAggregator implements SizedBucketAg
107107 private boolean starTreeDateRoundingRequired = true ;
108108
109109 private final FilterRewriteOptimizationContext filterRewriteOptimizationContext ;
110- public final String STARTREE_TIMESTAMP_FIELD = "@timestamp" ;
110+ public final String fieldName ;
111111
112112 DateHistogramAggregator (
113113 String name ,
@@ -172,6 +172,9 @@ protected Function<Long, Long> bucketOrdProducer() {
172172 }
173173 };
174174 filterRewriteOptimizationContext = new FilterRewriteOptimizationContext (bridge , parent , subAggregators .length , context );
175+ this .fieldName = (valuesSource instanceof ValuesSource .Numeric .FieldData )
176+ ? ((ValuesSource .Numeric .FieldData ) valuesSource ).getIndexFieldName ()
177+ : null ;
175178 this .starTreeDateDimension = (context .getQueryShardContext ().getStarTreeQueryContext () != null )
176179 ? fetchStarTreeCalendarUnit ()
177180 : null ;
@@ -244,13 +247,13 @@ private String fetchStarTreeCalendarUnit() {
244247 .next ();
245248 DateDimension starTreeDateDimension = (DateDimension ) compositeMappedFieldType .getDimensions ()
246249 .stream ()
247- .filter (dim -> dim .getField ().equals (STARTREE_TIMESTAMP_FIELD ))
250+ .filter (dim -> dim .getField ().equals (fieldName ))
248251 .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 )));
250253
251254 DateTimeUnitAdapter dateTimeUnitRounding = new DateTimeUnitAdapter (this .rounding .unit ());
252255 DateTimeUnitRounding rounding = starTreeDateDimension .findClosestValidInterval (dateTimeUnitRounding );
253- String dimensionName = STARTREE_TIMESTAMP_FIELD + "_" + rounding .shortName ();
256+ String dimensionName = fieldName + "_" + rounding .shortName ();
254257 if (rounding .shortName ().equals (this .rounding .unit ().shortName ())) {
255258 this .starTreeDateRoundingRequired = false ;
256259 }
0 commit comments