Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 339
O. San Avatar asked Jan 24 '26 13:01

O. San


1 Answers

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.

like image 175
izolight Avatar answered Jan 26 '26 06:01

izolight



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!