From e6155346203b9ecf95ef9a25994da76654e2b187 Mon Sep 17 00:00:00 2001 From: Joshua Powers Date: Wed, 29 Sep 2021 07:50:44 -0600 Subject: [PATCH] feat: add debug query output to elasticsearch_query (#9827) --- .../inputs/elasticsearch_query/aggregation_query.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/plugins/inputs/elasticsearch_query/aggregation_query.go b/plugins/inputs/elasticsearch_query/aggregation_query.go index b5fa9db3c..51bdd98e7 100644 --- a/plugins/inputs/elasticsearch_query/aggregation_query.go +++ b/plugins/inputs/elasticsearch_query/aggregation_query.go @@ -2,6 +2,7 @@ package elasticsearch_query import ( "context" + "encoding/json" "fmt" "strings" "time" @@ -34,6 +35,16 @@ func (e *ElasticsearchQuery) runAggregationQuery(ctx context.Context, aggregatio query = query.Filter(elastic5.NewQueryStringQuery(filterQuery)) query = query.Filter(elastic5.NewRangeQuery(aggregation.DateField).From(from).To(now)) + src, err := query.Source() + if err != nil { + return nil, fmt.Errorf("failed to get query source - %v", err) + } + data, err := json.Marshal(src) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal response - %v", err) + } + e.Log.Debugf("{\"query\": %s}", string(data)) + search := e.esClient.Search().Index(aggregation.Index).Query(query).Size(0) // add only parent elastic.Aggregations to the search request, all the rest are subaggregations of these