一尘不染

Elasticsearch-NoNodeAvailableException

elasticsearch

当尝试使用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)

阅读 289

收藏
2020-06-22

共1个答案

一尘不染

@AndreiStefan通过他链接的帖子为我的问题提供了解决方案。解决方案非常简单:

network.bind_host: 0

感谢你们。

2020-06-22