diff --git a/pkg/tsdb/elasticsearch/time_series_query.go b/pkg/tsdb/elasticsearch/time_series_query.go index 29bef578882..70fe16ba9d7 100644 --- a/pkg/tsdb/elasticsearch/time_series_query.go +++ b/pkg/tsdb/elasticsearch/time_series_query.go @@ -251,7 +251,14 @@ func addDateHistogramAgg(aggBuilder es.AggBuilder, bucketAgg *BucketAgg, timeFro a.Format = bucketAgg.Settings.Get("format").MustString(es.DateFormatEpochMS) if a.FixedInterval == "auto" { - a.FixedInterval = "$__interval" + // note this is not really a valid grafana-variable-handling, + // because normally this would not match `$__interval_ms`, + // but because how we apply these in the go-code, this will work + // correctly, and becomes something like `500ms`. + // a nicer way would be to use `${__interval_ms}ms`, but + // that format is not recognized where we apply these variables + // in the elasticsearch datasource + a.FixedInterval = "$__interval_msms" } if offset, err := bucketAgg.Settings.Get("offset").String(); err == nil { diff --git a/pkg/tsdb/elasticsearch/time_series_query_test.go b/pkg/tsdb/elasticsearch/time_series_query_test.go index a1572f35c83..3834ba0238a 100644 --- a/pkg/tsdb/elasticsearch/time_series_query_test.go +++ b/pkg/tsdb/elasticsearch/time_series_query_test.go @@ -399,7 +399,7 @@ func TestExecuteTimeSeriesQuery(t *testing.T) { require.Equal(t, firstLevel.Aggregation.Type, "date_histogram") hAgg := firstLevel.Aggregation.Aggregation.(*es.DateHistogramAgg) require.Equal(t, hAgg.Field, "@timestamp") - require.Equal(t, hAgg.FixedInterval, "$__interval") + require.Equal(t, hAgg.FixedInterval, "$__interval_msms") require.Equal(t, hAgg.MinDocCount, 2) t.Run("Should not include time_zone when timeZone is utc", func(t *testing.T) {