无法连接到弹性搜索:找不到活动连接:没有可用的Elasticsearch节点 [英] Cannot connect to elastic search : no active connection found: no Elasticsearch node available

查看:69
本文介绍了无法连接到弹性搜索:找不到活动连接:没有可用的Elasticsearch节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I just cannot understand what is happening. My go application is unable to connect to elastic search. The node is available, is up and running. What am I doing wrong here?

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")
}

这里有什么不正确的地方?错误显示未找到活动连接:没有可用的Elasticsearch节点

What is incorrect here? The error says no active connection found: no Elasticsearch node available

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

Here is the data returned from elastic search when I hit the GET request in browser

  {
"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"

}

推荐答案

错误未找到活动的连接:没有可用的Elasticsearch节点通常在您保留

Error no active connection found: no Elasticsearch node available usually happens when you keep sniffing in client enabled but your cluster doesn't have any nodes available. You can check status of your cluster by hitting: http://host:port/_nodes/http?pretty=true.

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

If you don't disable sniffing elastic Golang client will run process in background that polls /_nodes API (URL above) every 15 minutes and maintains list of healthy nodes. If there are no healthy nodes it ends with this error.

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

This can happen (NOTE: we had chat with OP where we debugged issue) also when your cluster is configured with private IPs (so in /_nodes API output you see private and not public IPs). Client with sniffing starts polling, gets the list of nodes and tries to connect to private IP but gets HTTP error because such node doesn't respond (or can't be even resolved in network where client is). So it marks it dead and progresses to other one. When there are no further nodes in cluster it reports no active connection found: no Elasticsearch node available.

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

To disable sniffing on client side (and to connect directly to specified node - but without any resiliency) you need to add &sniff=false to Elastic URL.

可以像这样进行连接:

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

这篇关于无法连接到弹性搜索:找不到活动连接:没有可用的Elasticsearch节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆