java Elasticsearch - NoNodeAvailableException
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33691858/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Elasticsearch - NoNodeAvailableException
提问by Carlos Vega
I get the following error when trying to connect to Elasticsearch 2 using the Java API for ES 2. This is the code:
尝试使用 ES 2 的 Java API 连接到 Elasticsearch 2 时出现以下错误。这是代码:
Settings settings = Settings.settingsBuilder().put("cluster.name", Receptor.clusterName).build();
TransportClient transportClient = TransportClient.builder().settings(settings).build();
Client c = null;
try {
c = transportClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(Receptor.es_ip), 9300));
} catch (UnknownHostException e) {
System.err.println(Util.getTimestampStr() + "UnknownHostException error.");
e.printStackTrace();
}
CreateIndexRequestBuilder createIndexRequestBuilder = c.admin().indices().prepareCreate(indexName);
createIndexRequestBuilder.addMapping(documentName, json);
createIndexRequestBuilder.execute().actionGet();
I'm able to get my ES node on the transportClient.connectedNodes() but when I try to add a new mapping I get the NoNodeAvailableExceptionexception. This code worked with previous versions of Elasticsearch. Any idea of what's wrong?
我可以在 transportClient.connectedNodes() 上获取我的 ES 节点,但是当我尝试添加新映射时,我收到了NoNodeAvailableException异常。此代码适用于以前版本的 Elasticsearch。知道出了什么问题吗?
NoNodeAvailableException[None of the configured nodes are available:
[]] at
org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:280)
at
org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:197)
at
org.elasticsearch.client.transport.support.TransportProxyClient.execute(TransportProxyClient.java:55)
at
org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:272)
at
org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:347)
at
org.elasticsearch.client.support.AbstractClient$IndicesAdmin.execute(AbstractClient.java:1177)
at
org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:85)
at
org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:59)
采纳答案by Carlos Vega
@AndreiStefan gave the solution to my problem thanks to the post he linked. The solution was as straightforward as:
由于他链接的帖子,@AndreiStefan 为我的问题提供了解决方案。解决方案非常简单:
network.bind_host: 0
Thank you guys.
感谢你们。
回答by Torrence
This problem could due to the network problem, if you are using network.host: _site_
in elasticsearch.yml AND sniffed TransportClient
connection, i.e. multiple site-local addresses are available within the machine hosting es node.
这个问题可能是由于网络问题,如果你network.host: _site_
在 elasticsearch.yml 和sniffed TransportClient
连接中使用,即在托管 es 节点的机器内有多个站点本地地址可用。
If you disable the sniff configuration, and the NoNodeAvailableException disappears, then you should double check the network configuration.
如果您禁用嗅探配置,并且 NoNodeAvailableException 消失,那么您应该仔细检查网络配置。
Get the nodes stat
获取节点状态
GET /_nodes
and check in the result to find transport
configuration, i.e.
并检查结果以找到transport
配置,即
"transport": {
"bound_address": [
"192.168.1.84:9300",
"172.29.0.1:9300"
],
"publish_address": "172.29.0.1:9300",
"profiles": {}
},
If there are multiple site-local addresses, the network.publish_host
that sniffed TransportClient will connect to, might be an unexpected address, because
如果有多个站点本地地址,network.publish_host
嗅探到的 TransportClient 将连接到,可能是一个意外的地址,因为
If not specified, this defaults to the “best” address from network.host, sorted by IPv4/IPv6 stack preference, then by reachability.
如果未指定,则默认为 network.host 中的“最佳”地址,按 IPv4/IPv6 堆栈首选项排序,然后按可达性排序。
To solve it, simple specify the network.publish_host
要解决它,只需指定 network.publish_host
network.publish_host: $DESIRED_IP_ADDRESS
network.publish_host: $DESIRED_IP_ADDRESS
in elasticsearch.yml.
在 elasticsearch.yml 中。
回答by crigore
The problem might be in the settings that you are using.
问题可能出在您使用的设置中。
Instead of creating the Client in these three steps:
而不是在这三个步骤中创建客户端:
TransportClient transportClient = TransportClient.builder().settings(settings).build();
Client c = null;
try {
c = transportClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(Receptor.es_ip), 9300));
} catch (UnknownHostException e) {
System.err.println(Util.getTimestampStr() + "UnknownHostException error.");
e.printStackTrace();
}
Try creating it like this:
尝试像这样创建它:
Client client = new TransportClient()
.addTransportAddress(new InetSocketTransportAddress(
InetAddress.getByName(Receptor.es_ip),
9300));
If you want more data check this old answer to a similar question: Elastic search problems
如果您想要更多数据,请查看类似问题的旧答案:弹性搜索问题