Skip to content

Commit f4aa98f

Browse files
fix: sql query with version 6.x
1 parent 6ff2d72 commit f4aa98f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

modules/elastic/api/proxy.go

+10
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ func (h *APIHandler) HandleProxyAction(w http.ResponseWriter, req *http.Request,
8080
}
8181
if strings.Trim(newURL.Path, "/") == "_sql" {
8282
distribution := esClient.GetVersion().Distribution
83+
version := esClient.GetVersion().Number
8384
indexName, err := rewriteTableNamesOfSqlRequest(req, distribution)
8485
if err != nil {
8586
h.WriteError(w, err.Error(), http.StatusInternalServerError)
@@ -92,6 +93,15 @@ func (h *APIHandler) HandleProxyAction(w http.ResponseWriter, req *http.Request,
9293
q, _ := url.ParseQuery(newURL.RawQuery)
9394
hasFormat := q.Has("format")
9495
switch distribution {
96+
case elastic.Elasticsearch:
97+
if !hasFormat {
98+
q.Add("format", "txt")
99+
}
100+
if large, _ := util.VersionCompare(version, "7.0.0"); large > 0 {
101+
path = "_sql?" + q.Encode()
102+
} else {
103+
path = "_xpack/_sql?" + q.Encode()
104+
}
95105
case elastic.Opensearch:
96106
path = "_plugins/_sql?format=raw"
97107
case elastic.Easysearch:

0 commit comments

Comments
 (0)