Elasticsearch: Use _field_caps instead of _mapping to get fields (#97607)
This commit is contained in:
@@ -182,14 +182,21 @@ func (s *Service) getDSInfo(ctx context.Context, pluginCtx backend.PluginContext
|
||||
return &instance, nil
|
||||
}
|
||||
|
||||
func isFieldCaps(url string) bool {
|
||||
return strings.HasSuffix(url, "/_field_caps") || url == "_field_caps"
|
||||
}
|
||||
|
||||
func (s *Service) CallResource(ctx context.Context, req *backend.CallResourceRequest, sender backend.CallResourceResponseSender) error {
|
||||
logger := s.logger.FromContext(ctx)
|
||||
// allowed paths for resource calls:
|
||||
// - empty string for fetching db version
|
||||
// - /_mapping for fetching index mapping, e.g. requests going to `index/_mapping`
|
||||
// - /_field_caps for fetching field capabilities, e.g. requests going to `index/_field_caps`
|
||||
// - _msearch for executing getTerms queries
|
||||
// - _mapping for fetching "root" index mappings
|
||||
if req.Path != "" && !strings.HasSuffix(req.Path, "/_mapping") && req.Path != "_msearch" && req.Path != "_mapping" {
|
||||
// - _field_caps for fetching "root" field capabilities
|
||||
if req.Path != "" && !isFieldCaps(req.Path) && req.Path != "_msearch" &&
|
||||
!strings.HasSuffix(req.Path, "/_mapping") && req.Path != "_mapping" {
|
||||
logger.Error("Invalid resource path", "path", req.Path)
|
||||
return fmt.Errorf("invalid resource URL: %s", req.Path)
|
||||
}
|
||||
@@ -266,6 +273,9 @@ func createElasticsearchURL(req *backend.CallResourceRequest, ds *es.DatasourceI
|
||||
}
|
||||
|
||||
esUrl.Path = path.Join(esUrl.Path, req.Path)
|
||||
if isFieldCaps(req.Path) {
|
||||
esUrl.RawQuery = "fields=*"
|
||||
}
|
||||
esUrlString := esUrl.String()
|
||||
// If the request path is empty and the URL does not end with a slash, add a slash to the URL.
|
||||
// This ensures that for version checks executed to the root URL, the URL ends with a slash.
|
||||
|
||||
Reference in New Issue
Block a user