Elasticsearch in Go, Err: "the client noticed that the server is not Elasticsearch and we do not support this unknown product"

huangapple go评论93阅读模式
英文:

Elasticsearch in Go, Err: "the client noticed that the server is not Elasticsearch and we do not support this unknown product"

问题

我正在使用Go语言中的Elasticsearch,我按照这个指南进行操作:https://developer.okta.com/blog/2021/04/23/elasticsearch-go-developers-guide

我使用docker设置了Elasticsearch。
验证Elasticsearch是否正在运行:

$ curl http://localhost:9200
{
  "name" : "0e9e2916eca5",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "jh8PVKNASpO3uK87Jzoq6Q",
  "version" : {
    "number" : "7.5.2",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "8bec50e1e0ad29dad5653712cf3bb580cd1afcdf",
    "build_date" : "2020-01-15T12:11:52.313576Z",
    "build_snapshot" : false,
    "lucene_version" : "8.3.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

从浏览器上看也没问题。

接下来,我设置了一个简单的Go程序来进行测试:

package main

import (
	"testing"
	"github.com/elastic/go-elasticsearch/v8"
)

func Test_elastic(t *testing.T) {

	es, err := elasticsearch.NewDefaultClient()
    if err != nil {
   	 panic(err)
    }

    res, err := es.Info()
    if err != nil {
   	 panic(err)
    }
    defer res.Body.Close()
}

但是res返回了一个错误:

> "the client noticed that the server is not Elasticsearch and we do not
> support this unknown product"

我查看了代码,发现它通过查找header.Get("X-Elastic-Product") == "Elasticsearch"来验证响应。

我不知道为什么它不起作用,也找不到关于这个错误的任何参考...希望能得到任何关于这个问题的帮助。

英文:

I'm working on using Elasticsearch in Go, I followed this guide: https://developer.okta.com/blog/2021/04/23/elasticsearch-go-developers-guide

I set up Elastic with docker.
Verify that Elasticsearch is running:

$ curl http://localhost:9200
{
  "name" : "0e9e2916eca5",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "jh8PVKNASpO3uK87Jzoq6Q",
  "version" : {
    "number" : "7.5.2",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "8bec50e1e0ad29dad5653712cf3bb580cd1afcdf",
    "build_date" : "2020-01-15T12:11:52.313576Z",
    "build_snapshot" : false,
    "lucene_version" : "8.3.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

Also from the browser seems fine.

Next I set up a sample Go program just to test it out:

package main

import (
	"testing"
	"github.com/elastic/go-elasticsearch/v8"
)

func Test_elastic(t *testing.T) {

	es, err := elasticsearch.NewDefaultClient()
    if err != nil {
   	 panic(err)
    }

    res, err := es.Info()
    if err != nil {
   	 panic(err)
    }
    defer res.Body.Close()
}

but res returns with err:

> "the client noticed that the server is not Elasticsearch and we do not
> support this unknown product"

Digging in the code I see it verifies the response by looking for header.Get("X-Elastic-Product") == "Elasticsearch".

I have no idea why it's not working and I couldn't find any reference for this error online... would appreciate any input on this.

答案1

得分: 18

你正在使用elasticsearch客户端的v8版本,但elasticsearch本身的版本是v7.5.2。你需要使用与elasticsearch版本对应的库版本,例如github.com/elastic/go-elasticsearch/v7。似乎最近才添加了对头部的检查,以防止该库与任何分支一起工作。

英文:

You are using v8 of the elasticsearch client, but v7.5.2 of elasticsearch itself. You need to use the library version corresponding to the elasticsearch version, like github.com/elastic/go-elasticsearch/v7. It seems that the check for the header was only added recently in order to not make the library work with any forks.

答案2

得分: 5

添加到@izolight的答案中,您可以使用任何适合您的旧版本,并且其中没有添加验证的版本。go-elasticsearchv7.13.1v6.8.10是最新的版本,没有产品检查。

go.mod:

	github.com/elastic/go-elasticsearch/v7 v7.13.1
    github.com/elastic/go-elasticsearch/v6 v6.8.10

sample.go:

package main

import (
    "testing"
    "github.com/elastic/go-elasticsearch/v7"
)

func Test_elastic(t *testing.T) {

    es, err := elasticsearch.NewDefaultClient()
    if err != nil {
     panic(err)
    }

    res, err := es.Info()
    if err != nil {
     panic(err)
    }
    defer res.Body.Close()
}

离题:

通过这样做,Elasticsearch的分支(如OpenSearch)将无法使用go-elasticsearch客户端。其他客户端库也添加了相同的产品检查,比如elastic/elasticsearch-py

作为回应,亚马逊计划分叉客户端库,并像OpenSearch一样维护它们。

英文:

Adding to @izolight's answer, You can use any old version that works for you and where the validation is not added. The go-elasticsearch v7.13.1 and v6.8.10 are the latest versions without the product check.

go.mod:

	github.com/elastic/go-elasticsearch/v7 v7.13.1
    github.com/elastic/go-elasticsearch/v6 v6.8.10

sample.go:

package main

import (
    "testing"
    "github.com/elastic/go-elasticsearch/v7"
)

func Test_elastic(t *testing.T) {

    es, err := elasticsearch.NewDefaultClient()
    if err != nil {
     panic(err)
    }

    res, err := es.Info()
    if err != nil {
     panic(err)
    }
    defer res.Body.Close()
}

Off-Topic:

By doing this, the Elasticsearch forks like OpenSearch won't be able to use go-elasticsearch client. Same product checks are added to other client libraries, say elastic/elasticsearch-py.

In response, Amazon has planned to fork the Client libraries too and maintain them as like OpenSearch.

答案3

得分: 1

只是一个小提示,如果你正在针对ES编写测试,并且在按照建议使用模拟的自定义http.Transport时遇到了这个问题,请确保你的模拟响应包括头部信息,就像在https://github.com/elastic/go-elasticsearch/blob/main/elasticsearch_internal_test.go#L53中所看到的那样。

英文:

Just a side note that if you are writing tests against ES and running into this issue when following the recommendation to use a mock for a custom http.Transport, make sure your mock response includes the headers, as seen at https://github.com/elastic/go-elasticsearch/blob/main/elasticsearch_internal_test.go#L53

huangapple
  • 本文由 发表于 2021年8月16日 19:50:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/68802324.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定