feat: add debug query output to elasticsearch_query (#9827)

This commit is contained in:
Joshua Powers 2021-09-29 07:50:44 -06:00 committed by GitHub
parent 56398237c4
commit e615534620
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 0 deletions

View File

@ -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