no active connection found: no Elasticsearch node available

发布时间:2021-08-16 14:18:06


使用的第三方库"gopkg.in/olivere/elastic.v5"

no active connection found: no Elasticsearch node available

解决

Docker No Elastic Node Aviable

关闭sniff模式;或者设置es的地址为publish_address 地址

代码设置sniff 为false

client, err := elastic.NewClient(elastic.SetSniff(false), elastic.SetURL(url))


分析

It has to do something with the way sniffing works (see details in the Wiki). The node IPs are probably not accessible from your application.When you enable sniffing, it will retrieve the node IPs from the http.publish_address. And that seems to be routeable

查看publish_address

curl -XGET '0.0.0.0:9200/_nodes/http?pretty'


{

  "_nodes" : {

    "total" : 1,

    "successful" : 1,

    "failed" : 0

  },

  "cluster_name" : "docker-cluster",

  "nodes" : {

    "L2wRBV1sSwaLcIiEq6L23g" : {

      "name" : "bc9b00a7d4ff",

      "transport_address" : "172.17.0.2:9300",

      "host" : "172.17.0.2",

      "ip" : "172.17.0.2",

      "version" : "7.4.2",

      "build_flavor" : "default",

      "build_type" : "docker",

      "build_hash" : "2f90bbf7b93631e52bafb59b3b049cb44ec25e96",

      "roles" : [

        "ingest",

        "master",

        "data",

        "ml"

      ],

      "attributes" : {

        "ml.machine_memory" : "2084691968",

        "xpack.installed" : "true",

        "ml.max_open_jobs" : "20"

      },

      "http" : {

        "bound_address" : [

          "0.0.0.0:9200"

        ],

        "publish_address" : "172.17.0.2:9200",

        "max_content_length_in_bytes" : 104857600

      }

    }

  }

}