Exception in thread "main" NoNodeAvailableException[None of the configured nodes are available: [{#t

elasticsearch2.3.4

Map map = new HashMap();
Settings.Builder settings = Settings.builder().put(map);
Client client = TransportClient.builder().settings(settings).build()
                .addTransportAddress(new InetSocketTransportAddress(
                        InetAddress.getByName("localhost"), Integer.parseInt("9200")));
IndexRequestBuilder indexRequestBuilder = client.prepareIndex(RULE_INDEX, RULE_INDEX_TYPE, id);
IndexResponse response = indexRequestBuilder.setSource(json).execute().actionGet();
client.close();

信息: [Yukio] failed to get node info for {#transport#-1}{127.0.0.1}{localhost/127.0.0.1:9200}, disconnecting...
ReceiveTimeoutTransportException[[][localhost/127.0.0.1:9200][cluster:monitor/nodes/liveness] request_id [0] timed out after [5001ms]]
	at org.elasticsearch.transport.TransportService$TimeoutHandler.run(TransportService.java:679)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)

Exception in thread "main" NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{127.0.0.1}{localhost/127.0.0.1:9200}]]
	at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:290)
	at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:207)
	at org.elasticsearch.client.transport.support.TransportProxyClient.execute(TransportProxyClient.java:55)
	at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:288)
	at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:359)
	at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:86)
	at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:56)
	at com.es.plugin.EsOperationServiceTest.main(EsOperationServiceTest.java:50)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

解决:如果你配置了es集群的cluster.name,则需要在settings中添加cluster.name的名字,如果没有修改端口号,则客户端的端口号为9300。

Map map = new HashMap();
map.put("cluster.name", "es_test");
Settings.Builder settings = Settings.builder().put(map);
Client client = TransportClient.builder().settings(settings).build()
                .addTransportAddress(new InetSocketTransportAddress(
                        InetAddress.getByName("localhost"), Integer.parseInt("9300")));

再次运行问题解决。

参考:http://stackoverflow.com/questions/25912572/java-elasticsearch-none-of-the-configured-nodes-are-available



你可能感兴趣的:(java)