From ca52a5b00d237e0fe2e3de0bec8464b0a8bcca8c Mon Sep 17 00:00:00 2001 From: Hardy Date: Fri, 21 Feb 2025 15:06:10 +0800 Subject: [PATCH] fix: sql query with elasticsearch version 6.x (#158) * fix: sql query with version 6.x * docs: update release notes * docs: typo release notes --------- Co-authored-by: hardy --- docs/content.en/docs/release-notes/_index.md | 5 +++-- docs/content.zh/docs/release-notes/_index.md | 5 +++-- modules/elastic/api/proxy.go | 10 ++++++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/docs/content.en/docs/release-notes/_index.md b/docs/content.en/docs/release-notes/_index.md index 9816e081..7d3298ad 100644 --- a/docs/content.en/docs/release-notes/_index.md +++ b/docs/content.en/docs/release-notes/_index.md @@ -18,8 +18,9 @@ Information about release notes of INFINI Console is provided here. ### Bug fix - Fixed the error when querying empty metric data (#144) - Fixed empty host when setup step finishes (#147) -- Fixed the error of obtaining suggestions of field's value in discover -- Fixed the wrong display of heatmap's data in alerting message +- Fixed the error of obtaining suggestions of field's value in discover (#151) +- Fixed the wrong display of heatmap's data in alerting message (#157) +- Fixed Devtools `_sql` support for elasticsearch 6.x (#158) ### Improvements - Update agent config with cluster name (#148) diff --git a/docs/content.zh/docs/release-notes/_index.md b/docs/content.zh/docs/release-notes/_index.md index bb29436f..5d81dd3f 100644 --- a/docs/content.zh/docs/release-notes/_index.md +++ b/docs/content.zh/docs/release-notes/_index.md @@ -18,8 +18,9 @@ title: "版本历史" ### Bug fix - 修复指标数据为空时的查询错误 (#144) - 修复初始化结束步骤中主机显示为错误的问题 (#147) -- 修复数据探索中获取字段值建议的错误 -- 修复告警消息热图数据显示错误的问题 +- 修复数据探索中获取字段值建议的错误 (#151) +- 修复告警消息热图数据显示错误的问题 (#157) +- 修复开发工具 `_sql` 查询支撑 Elasticsearch 6.x 版本 (#158) ### Improvements - 优化下发给 Agent 的配置,增加集群名称 (#148) diff --git a/modules/elastic/api/proxy.go b/modules/elastic/api/proxy.go index b5f0b061..7add726a 100644 --- a/modules/elastic/api/proxy.go +++ b/modules/elastic/api/proxy.go @@ -80,6 +80,7 @@ func (h *APIHandler) HandleProxyAction(w http.ResponseWriter, req *http.Request, } if strings.Trim(newURL.Path, "/") == "_sql" { distribution := esClient.GetVersion().Distribution + version := esClient.GetVersion().Number indexName, err := rewriteTableNamesOfSqlRequest(req, distribution) if err != nil { h.WriteError(w, err.Error(), http.StatusInternalServerError) @@ -92,6 +93,15 @@ func (h *APIHandler) HandleProxyAction(w http.ResponseWriter, req *http.Request, q, _ := url.ParseQuery(newURL.RawQuery) hasFormat := q.Has("format") switch distribution { + case elastic.Elasticsearch: + if !hasFormat { + q.Add("format", "txt") + } + if large, _ := util.VersionCompare(version, "7.0.0"); large > 0 { + path = "_sql?" + q.Encode() + } else { + path = "_xpack/_sql?" + q.Encode() + } case elastic.Opensearch: path = "_plugins/_sql?format=raw" case elastic.Easysearch: