Reputation: 1177
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.
Upvotes: 15
Views: 37145
Reputation: 76
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
Upvotes: 3
Reputation: 13546
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.
Upvotes: 5
Reputation: 366
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.
Upvotes: 20