NoNodeAvailableException, cannot connect Java API and Elasticsearch

Hi all,

I am new to elasticsearch. I want to use Java API to communicate with ES cluster.
This is my code right now:

        Settings settings = ImmutableSettings.settingsBuilder()
			.put("client.transport.ping_timeout", "15s")
	        .put("client.transport.sniff", false)
	        .put("client.transport.nodes_sampler_interval", "15s")
	        .put("cluster.name", "storyteller")
	        .build();
	
	Client client = new TransportClient(settings)
	        .addTransportAddress(new InetSocketTransportAddress(XXX.XX.XXX.XX:9200));

        SearchResponse response = client.prepareSearch()
	        .setQuery(QueryBuilders.termQuery("hashtags", target))             // Query
	        .execute()
	        .actionGet();

The exception happens when SearchResponse is compiled at .execute();

The error message is this:

  2015-07-13 12:01:30.053  INFO 48741 --- [nio-8081-exec-9] org.elasticsearch.plugins [Constrictor] loaded [], sites []
  2015-07-13 12:01:30.397  INFO 48741 --- [io-8081-exec-10] org.elasticsearch.plugins                : [Wanda Maximoff] loaded [], sites []
  2015-07-13 12:01:45.175  INFO 48741 --- [][generic][T#2]] org.elasticsearch.client.transport       : [Constrictor] failed to get local cluster state for [#transport#-1][sea-zoushi-XX][inet[/XXX.XX.XXX.XX:9200]], disconnecting...

org.elasticsearch.transport.ReceiveTimeoutTransportException: [][inet[/XXX.XX.XXX.XX:9200]][cluster:monitor/state] request_id [0] timed out after [15004ms]
   at org.elasticsearch.transport.TransportService$TimeoutHandler.run(TransportService.java:529)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
   at java.lang.Thread.run(Thread.java:745)


2015-07-13 12:01:45.183 ERROR 48741 --- [nio-8081-exec-9] o.a.c.c.C.[.[.[.[dispatcherServlet]      : Servlet.service() for servlet [dispatcherServlet] in context with path [/storytellerconsumer] threw exception [Request processing failed; nested exception is            org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: []] with root cause

org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: []
at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:305)
at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:200)
at org.elasticsearch.client.transport.support.InternalTransportClient.execute(InternalTransportClient.java:106)
at org.elasticsearch.client.support.AbstractClient.search(AbstractClient.java:338)
at org.elasticsearch.client.transport.TransportClient.search(TransportClient.java:430)
at org.elasticsearch.action.search.SearchRequestBuilder.doExecute(SearchRequestBuilder.java:1112)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:91)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:65)
at com.cdk.storyteller.consumer.domain.MessageStore.search(MessageStore.java:106)

To be clear, I want to link to the ES which is created by docker, and I am using the IP of the ES on the grid.

I have searched a lot of related materials and discussions.
But I really do not know where the error could be.
Please help me.

Thank you in advance,
Shiqi

this is your problem, use port 9300 for the transport client not 9200

Thank you for replying.

I tried to use 9300 as the transport client, and I got a even more confusing error.

   2015-07-13 12:57:11.830  INFO 48808 --- [nio-8081-exec-8] org.elasticsearch.plugins                : [Anti-Phoenix Force] loaded [], sites []
2015-07-13 12:57:11.961 ERROR 48808 --- [nio-8081-exec-8] o.a.c.c.C.[.[.[.[dispatcherServlet]      : Servlet.service() for servlet [dispatcherServlet] in context with path [/storytellerconsumer] threw exception [Request processing failed; nested exception is   org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: []] with root cause

org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: []
at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:305)
at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:200)
at org.elasticsearch.client.transport.support.InternalTransportClient.execute(InternalTransportClient.java:106)
at org.elasticsearch.client.support.AbstractClient.search(AbstractClient.java:338)
at org.elasticsearch.client.transport.TransportClient.search(TransportClient.java:430)
at org.elasticsearch.action.search.SearchRequestBuilder.doExecute(SearchRequestBuilder.java:1112)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:91)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:65)
at com.cdk.storyteller.consumer.domain.MessageStore.search(MessageStore.java:106)

Only other two things I can think of is either the cluster name is wrong or port 9300 isn't open.

1 Like

I have create a a elasticsearch.yml file under src/main/resources/.
The content for it is:
"cluster.name: storyteller"
I am not sure whether it is the correct way to do it.

Or should I initialize the cluster's name when I create a cluster.
But I am using docker to create elastic search, so the cluster's name would be created when calling docker?

If I change the IP address to docker's ip or localhost ip, and port to 9300.
I get this:

2015-07-13 13:45:55.056  INFO 49188 --- [nio-8081-exec-8] org.elasticsearch.plugins                : [Vindaloo] loaded [], sites []
2015-07-13 13:45:55.145  WARN 49188 --- [nio-8081-exec-8] org.elasticsearch.client.transport       : [Vindaloo] node null not part of the cluster Cluster [storyteller], ignoring...
2015-07-13 13:45:55.155 ERROR 49188 --- [nio-8081-exec-8] o.a.c.c.C.[.[.[.[dispatcherServlet]      : Servlet.service() for servlet [dispatcherServlet] in context with path [/storytellerconsumer] threw exception [Request processing failed; nested exception is org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: []] with root cause

The cluster name should be kept in elasticsearch.yml like you said. Though I can't say for sure ES is finding the right file. The default ES cluster name is just "elasticsearch". Try sending a request to that cluster name instead and see what happens.

After I changed the cluster name to elasticsearch, I get this:

2015-07-13 13:55:35.763  INFO 49199 --- [nio-8081-exec-8] org.elasticsearch.plugins                : [Anomalito] loaded [], sites []
2015-07-13 13:55:36.219  INFO 49199 --- [nio-8081-exec-9] org.elasticsearch.plugins                : [Capricorn] loaded [], sites []
2015-07-13 13:56:05.944 ERROR 49199 --- [nio-8081-exec-8] o.a.c.c.C.[.[.[.[dispatcherServlet]      : Servlet.service() for servlet [dispatcherServlet] in context with path [/storytellerconsumer] threw exception [Request processing failed; nested exception is org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: []] with root cause

org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: []
at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:305)
at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:200)
at org.elasticsearch.client.transport.support.InternalTransportClient.execute(InternalTransportClient.java:106)
at org.elasticsearch.client.support.AbstractClient.search(AbstractClient.java:338)
at org.elasticsearch.client.transport.TransportClient.search(TransportClient.java:430)
at org.elasticsearch.action.search.SearchRequestBuilder.doExecute(SearchRequestBuilder.java:1112)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:91)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:65)
at com.cdk.storyteller.consumer.domain.MessageStore.search(MessageStore.java:106)

I would recommend taking a step back and installing the Head plugin so you can get a view of your cluster, it will also display the cluster name at the top.

Also maybe try sending a simple index request from the command line to make sure you can connect to your cluster at all.

Thank you!

This is the issue of version. follow this link to look into details