# NoNodeAvailableException, cannot connect Java API and Elasticsearch

**URL:** https://discuss.elastic.co/t/nonodeavailableexception-cannot-connect-java-api-and-elasticsearch/25474
**Category:** Elasticsearch
**Created:** [July 13, 2015, 7:14pm UTC](https://discuss.elastic.co/t/nonodeavailableexception-cannot-connect-java-api-and-elasticsearch/25474 "2015-07-13T19:14:01Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![MagicZou](https://avatars.discourse-cdn.com/v4/letter/m/eb8c5e/32.png) [@MagicZou](https://discuss.elastic.co/u/MagicZou)
#### Post date: [July 13, 2015, 7:14pm UTC](https://discuss.elastic.co/t/nonodeavailableexception-cannot-connect-java-api-and-elasticsearch/25474/1 "2015-07-13T19:14:02Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Harlin\_ES](https://avatars.discourse-cdn.com/v4/letter/h/977dab/32.png) [@Harlin\_ES](https://discuss.elastic.co/u/Harlin_ES)
#### Post date: [July 13, 2015, 7:47pm UTC](https://discuss.elastic.co/t/nonodeavailableexception-cannot-connect-java-api-and-elasticsearch/25474/2 "2015-07-13T19:47:34Z")

</div>

> [@MagicZou](#):
>
> Client client = new TransportClient(settings)  
> .addTransportAddress(new InetSocketTransportAddress(XXX.XX.XXX.XX:9200));

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

---

<div class="post-metadata">

### Author: ![MagicZou](https://avatars.discourse-cdn.com/v4/letter/m/eb8c5e/32.png) [@MagicZou](https://discuss.elastic.co/u/MagicZou)
#### Post date: [July 13, 2015, 8:00pm UTC](https://discuss.elastic.co/t/nonodeavailableexception-cannot-connect-java-api-and-elasticsearch/25474/3 "2015-07-13T20:00:12Z")

</div>

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)
```

---

<div class="post-metadata">

### Author: ![Harlin\_ES](https://avatars.discourse-cdn.com/v4/letter/h/977dab/32.png) [@Harlin\_ES](https://discuss.elastic.co/u/Harlin_ES)
#### Post date: [July 13, 2015, 8:28pm UTC](https://discuss.elastic.co/t/nonodeavailableexception-cannot-connect-java-api-and-elasticsearch/25474/4 "2015-07-13T20:28:25Z")

</div>

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

---

<div class="post-metadata">

### Author: ![MagicZou](https://avatars.discourse-cdn.com/v4/letter/m/eb8c5e/32.png) [@MagicZou](https://discuss.elastic.co/u/MagicZou)
#### Post date: [July 13, 2015, 8:35pm UTC](https://discuss.elastic.co/t/nonodeavailableexception-cannot-connect-java-api-and-elasticsearch/25474/5 "2015-07-13T20:35:31Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![MagicZou](https://avatars.discourse-cdn.com/v4/letter/m/eb8c5e/32.png) [@MagicZou](https://discuss.elastic.co/u/MagicZou)
#### Post date: [July 13, 2015, 8:51pm UTC](https://discuss.elastic.co/t/nonodeavailableexception-cannot-connect-java-api-and-elasticsearch/25474/6 "2015-07-13T20:51:44Z")

</div>

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
```

---

<div class="post-metadata">

### Author: ![Harlin\_ES](https://avatars.discourse-cdn.com/v4/letter/h/977dab/32.png) [@Harlin\_ES](https://discuss.elastic.co/u/Harlin_ES)
#### Post date: [July 13, 2015, 8:53pm UTC](https://discuss.elastic.co/t/nonodeavailableexception-cannot-connect-java-api-and-elasticsearch/25474/7 "2015-07-13T20:53:00Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![MagicZou](https://avatars.discourse-cdn.com/v4/letter/m/eb8c5e/32.png) [@MagicZou](https://discuss.elastic.co/u/MagicZou)
#### Post date: [July 13, 2015, 8:57pm UTC](https://discuss.elastic.co/t/nonodeavailableexception-cannot-connect-java-api-and-elasticsearch/25474/8 "2015-07-13T20:57:38Z")

</div>

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)
```

---

<div class="post-metadata">

### Author: ![Harlin\_ES](https://avatars.discourse-cdn.com/v4/letter/h/977dab/32.png) [@Harlin\_ES](https://discuss.elastic.co/u/Harlin_ES)
#### Post date: [July 13, 2015, 9:43pm UTC](https://discuss.elastic.co/t/nonodeavailableexception-cannot-connect-java-api-and-elasticsearch/25474/9 "2015-07-13T21:43:44Z")

</div>

I would recommend taking a step back and installing the [Head plugin](http://mobz.github.io/elasticsearch-head/) 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.

---

<div class="post-metadata">

### Author: ![MagicZou](https://avatars.discourse-cdn.com/v4/letter/m/eb8c5e/32.png) [@MagicZou](https://discuss.elastic.co/u/MagicZou)
#### Post date: [July 13, 2015, 9:50pm UTC](https://discuss.elastic.co/t/nonodeavailableexception-cannot-connect-java-api-and-elasticsearch/25474/11 "2015-07-13T21:50:23Z")

</div>

Thank you!

---

<div class="post-metadata">

### Author: ![qsiddiqui81](https://avatars.discourse-cdn.com/v4/letter/q/8edcca/32.png) [@qsiddiqui81](https://discuss.elastic.co/u/qsiddiqui81)
#### Post date: [November 10, 2015, 5:16am UTC](https://discuss.elastic.co/t/nonodeavailableexception-cannot-connect-java-api-and-elasticsearch/25474/12 "2015-11-10T05:16:50Z")

</div>

This is the issue of version. follow this link to look into [details](http://frustrateddevelopers.com/2015/11/none-of-the-configured-nodes-are-available/?utm_campaign=shareaholic&utm_medium=google_plus&utm_source=socialnetwork)

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [July 5, 2017, 11:39pm UTC](https://discuss.elastic.co/t/nonodeavailableexception-cannot-connect-java-api-and-elasticsearch/25474/13 "2017-07-05T23:39:35Z")

</div>


