I get the following error when trying to connect to Elasticsearch 2 using the Java API for ES 2. This is the code:
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 NoNodeAvailableException exception. This code worked with previous versions of Elasticsearch. Any idea of what's wrong?
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)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…