Files
grafana/pkg/tsdb/elasticsearch/data_query_validator.go
T
Andrew Hackmann 9c6feb8de5 Elasticsearch: Builder queries no longer execute in code mode (#115456)
* The builder query no longer runs if code mode query is empty. Remove checks for query being empty to run raw query.

* missed save

* prettier?

* Update public/app/plugins/datasource/elasticsearch/components/QueryEditor/BucketAggregationsEditor/state/reducer.ts

Co-authored-by: Andreas Christou <andreas.christou@grafana.com>

---------

Co-authored-by: Andreas Christou <andreas.christou@grafana.com>
2025-12-30 15:37:19 +00:00

41 lines
1.3 KiB
Go

package elasticsearch
import (
"fmt"
)
// isQueryWithError validates the query and returns an error if invalid
func isQueryWithError(query *Query) error {
// Skip validation for raw DSL queries because no easy way to see it is valid without just running it
if query.EditorType != nil && *query.EditorType == "code" {
return nil
}
if len(query.BucketAggs) == 0 {
// If no aggregations, only document and logs queries are valid
if len(query.Metrics) == 0 || (!isLogsQuery(query) && !isDocumentQuery(query)) {
return fmt.Errorf("invalid query, missing metrics and aggregations")
}
}
return nil
}
// isLogsQuery checks if the query is a logs query
func isLogsQuery(query *Query) bool {
return len(query.Metrics) > 0 && query.Metrics[0].Type == logsType
}
// isDocumentQuery checks if the query is a document query (raw_data or raw_document)
func isDocumentQuery(query *Query) bool {
return isRawDataQuery(query) || isRawDocumentQuery(query)
}
// isRawDataQuery checks if the query is a raw_data query
func isRawDataQuery(query *Query) bool {
return len(query.Metrics) > 0 && query.Metrics[0].Type == rawDataType
}
// isRawDocumentQuery checks if the query is a raw_document query
func isRawDocumentQuery(query *Query) bool {
return len(query.Metrics) > 0 && query.Metrics[0].Type == rawDocumentType
}