尝试使用Java API for ES 2连接到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();
我能够在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)
答案 0 :(得分:7)
答案 1 :(得分:0)
问题可能出在您正在使用的设置中。
而不是通过以下三个步骤创建客户端:
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();
}
尝试像这样创建:
Client client = new TransportClient()
.addTransportAddress(new InetSocketTransportAddress(
InetAddress.getByName(Receptor.es_ip),
9300));
如果您想要更多数据,请查看类似问题的旧答案:Elastic search problems
答案 2 :(得分:0)
如果您在elasticsearch.yml和network.host: _site_
连接中使用sniffed TransportClient
,则可能是由于网络问题引起的,即在托管es节点的机器中有多个站点本地地址。
如果禁用嗅探配置,并且NoNodeAvailableException消失,则应仔细检查网络配置。
获取节点状态
GET /_nodes
并检查结果以找到transport
配置,即
"transport": {
"bound_address": [
"192.168.1.84:9300",
"172.29.0.1:9300"
],
"publish_address": "172.29.0.1:9300",
"profiles": {}
},
如果有多个站点本地地址,则嗅探到的TransportClient将连接到的network.publish_host
可能是意外地址,因为
如果未指定,则默认为network.host的“最佳”地址,按IPv4 / IPv6堆栈首选项,然后按可达性排序。
要解决此问题,只需指定network.publish_host
network.publish_host:$ DESIRED_IP_ADDRESS
在elasticsearch.yml中。