From 0f9168953b5571076a31a7cfdfc97f037d1ddf47 Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Tue, 22 Jun 2021 13:33:22 -0400 Subject: [PATCH] Elasticsearch: Restore fields naming when using variables (#35624) (#36034) (cherry picked from commit 185bf8f9a23e37c7fd521ea8dc3de44aace5fc77) Co-authored-by: Giordano Ricci --- .../datasource/elasticsearch/datasource.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/public/app/plugins/datasource/elasticsearch/datasource.ts b/public/app/plugins/datasource/elasticsearch/datasource.ts index 6a763b8277e..430ffbec938 100644 --- a/public/app/plugins/datasource/elasticsearch/datasource.ts +++ b/public/app/plugins/datasource/elasticsearch/datasource.ts @@ -35,6 +35,7 @@ import { import { bucketAggregationConfig } from './components/QueryEditor/BucketAggregationsEditor/utils'; import { BucketAggregation, + BucketAggregationWithField, isBucketAggregationWithField, } from './components/QueryEditor/BucketAggregationsEditor/aggregations'; import { generate, Observable, of, throwError } from 'rxjs'; @@ -388,7 +389,23 @@ export class ElasticDatasource extends DataSourceApi ({ + ...q, + bucketAggs: q.bucketAggs?.map((bucketAgg, aggIndex) => { + if (isBucketAggregationWithField(bucketAgg)) { + return { + ...bucketAgg, + field: (queries[queryIndex].bucketAggs?.[aggIndex] as BucketAggregationWithField).field, + }; + } + + return bucketAgg; + }), + })); } testDatasource() {