From d82b2add11d54840eec3a9c8eaa17c6a12bba967 Mon Sep 17 00:00:00 2001 From: Wanpl-Java <810220955@qq.com> Date: Thu, 23 Jul 2026 12:00:46 +0800 Subject: [PATCH] feat: support Elasticsearch 9 for command storage --- storage/es.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/storage/es.go b/storage/es.go index 8df51aa..3de43ea 100644 --- a/storage/es.go +++ b/storage/es.go @@ -30,6 +30,10 @@ func (es ESCommandStorage) BulkSave(commands []*model.Command) error { if es.IsEs8() { return es.BulkSaveEs8(commands) } + // 探测失败时也先试 Es8,避免 ES9 误走带 type 的旧接口 + if err := es.BulkSaveEs8(commands); err == nil { + return nil + } return es.BulkSaveEs(commands) } @@ -167,7 +171,8 @@ func (es ESCommandStorage) IsEs8() bool { if err2 := json.NewDecoder(resp.Body).Decode(&infoResp); err2 != nil { return false } - return infoResp.Version.Number[0] == '8' + major := infoResp.Version.Number[0] + return major == '8' || major == '9' } func (es ESCommandStorage) createEsClient() (*elasticsearch.Client, error) {