小编典典

无法连接到弹性搜索:找不到活动连接:没有可用的Elasticsearch节点

go

我只是不明白发生了什么。我的go应用程序无法连接到弹性搜索。该节点可用,已启动并正在运行。我在这里做错了什么?

import (
    "fmt"
    "github.com/olivere/elastic/v7"
    "github.com/sirupsen/logrus"
    "gitlab.com/codereverie/anuvadak-api-server/app_config"
    "gopkg.in/sohlich/elogrus.v7"
    "gopkg.in/validator.v2"
    "io"
    "os"
)

eurl := "http://ip:port"
eUsername := "username"
ePassword := "password"

client, err := elastic.NewClient(elastic.SetURL(eurl), elastic.SetBasicAuth(eUsername, ePassword))

if err != nil {
    fmt.Println("Some error", err.Error())
    panic("Failed to initialize elastic-search client")
}

这里有什么不对的地方?错误说no active connection found: no Elasticsearch node available

这是我在浏览器中命中GET请求时从弹性搜索返回的数据

  {
"name": "ABC-1",
"cluster_name": "ABC",
"cluster_uuid": "3oo05v6lSSmE7DpRh_68Yg",
"version": {
  "number": "7.6.2",
  "build_flavor": "default",
  "build_type": "deb",
  "build_hash": "ef48eb35cf30adf4db14086e8aabd07ef6fb113f",
  "build_date": "2020-03-26T06:34:37.794943Z",
  "build_snapshot": false,
  "lucene_version": "8.4.0",
  "minimum_wire_compatibility_version": "6.8.0",
  "minimum_index_compatibility_version": "6.0.0-beta1"
},
"tagline": "You Know, for Search"

}


阅读 275

收藏
2020-07-02

共1个答案

小编典典

no active connection found: no Elasticsearch node available当您继续在客户端中进行嗅探但群集没有可用节点时,通常会发生错误。您可以通过点击来检查集群的状态http://host:port/_nodes/http?pretty=true

如果您elastic不禁用嗅探功能,则Golang客户端将在后台运行进程,该进程/_nodes每15分钟轮询一次API(上面的URL)并维护正常节点列表。如果没有健康的节点,则以该错误结束。

当您的集群配置有私有IP时,也会发生这种情况(注意:我们在OP上进行了调试,我们调试了问题)(因此在/_nodesAPI输出中,您看到的是私有IP,而非公共IP)。具有嗅探功能的客户端开始轮询,获取节点列表并尝试连接到专用IP,但由于该节点无响应(甚至无法在客户端所在的网络中解决)而收到HTTP错误。因此,它标志着它已经死了并发展到另一个。当群集中没有其他节点时,它将报告no active connection found: no Elasticsearch node available

要在客户端禁用嗅探(并直接连接到指定节点-但没有任何弹性),您需要添加&sniff=false到Elastic URL。

可以这样进行连接:

config, _ := config.Parse("http://user:pwd@host:port/index&sniff=false")
client, _ := elastic.NewClientFromConfig(config)
2020-07-02