# ElasticSearch in Java (TransportClient): NoNodeAvailableException\[None of the configured nodesare available: \[\]\]

**URL:** <https://discuss.elastic.co/t/elasticsearch-in-java-transportclient-nonodeavailableexception-none-of-the-configured-nodesare-available/34452>\
**Category:** Elasticsearch\
**Created:** [November 12, 2015, 6:49pm UTC](https://discuss.elastic.co/t/elasticsearch-in-java-transportclient-nonodeavailableexception-none-of-the-configured-nodesare-available/34452 "2015-11-12T18:49:37Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![aliteralmind](https://avatars.discourse-cdn.com/v4/letter/a/c77e96/32.png) [@aliteralmind](https://discuss.elastic.co/u/aliteralmind)\
**Post date:** [November 12, 2015, 6:49pm UTC](https://discuss.elastic.co/t/elasticsearch-in-java-transportclient-nonodeavailableexception-none-of-the-configured-nodesare-available/34452/1 "2015-11-12T18:49:37Z")

</div>

I'm trying to make my first Java application to talk to ElasticSearch, which is running on this node (timestamps removed):

```
$ bin/elasticsearch
[2015...][WARN][bootstrap] Unable to lock JVM Memory: error=78,reason=Function not implemented
[2015...][WARN][bootstrap] This can result in part of the JVM being swapped out.
[2015...][INFO][node] [clustername.01] version[2.0.0], pid[49252], build[de54438/2015-10-22T08:09:48Z]
[2015...][INFO][node] [clustername.01] initializing ...
[2015...][INFO][plugins] [clustername.01] loaded [license, marvel], sites []
[2015...][INFO][env] [clustername.01] using [1] data paths, mounts [[/ (/dev/disk1)]], net usable_space [164.4gb], net total_space [232.5gb], spins? [unknown], types [hfs]
[2015...][INFO][node] [clustername.01] initialized
[2015...][INFO][node] [clustername.01] starting ...
[2015...][INFO][transport] [clustername.01] publish_address {127.0.0.1:9300}, bound_addresses {127.0.0.1:9300}
[2015...][INFO][discovery] [clustername.01] myusername-elasticsearch-local/AM4lm0ZBS_6FofhC0UbNIA
[2015...][INFO][cluster.service] [clustername.01] new_master {clustername.01}{AM4lm0ZBS_6FofhC0UbNIA}{127.0.0.1}{127.0.0.1:9300}, reason: zen-disco-join(elected_as_master, [0] joins received)
[2015...][INFO][http] [clustername.01] publish_address {127.0.0.1:9200}, bound_addresses {127.0.0.1:9200}
[2015...][INFO][node] [clustername.01] started
[2015...][INFO][license.plugin.core] [clustername.01] license [3ff50767-f1a5-4bac-8e35-c7a131384fd9] - valid
[2015...][ERROR][license.plugin.core] [clustername.01]
[2015...][INFO][gateway] [clustername.01] recovered [14] indices into cluster_state
```

I've [confirmed the IP and port](http://stackoverflow.com/a/14066524/2736496) is running:

```
$ bin/elasticsearch --version
Version: 2.0.0, Build: de54438/2015-10-22T08:09:48Z, JVM: 1.8.0_45
$ telnet 127.0.0.1 9300
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.

^CConnection closed by foreign host.
$ telnet 127.0.0.1 9301
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
telnet: Unable to connect to remote host
$
```

9300 is there, 9301 isn't. I'm [reasonably sure](https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-transport.html) that port 9300 is correct for a Java TransportClient.

But this

```
public class TrivialClient {

   public static void main(String[] args) throws UnknownHostException {
      Client client = TransportClient.builder().build().
      addTransportAddress(new InetSocketTransportAddress(
         InetAddress.getLocalHost(), 9300));
      printResponse("getLocalHost", client);
  
      client = TransportClient.builder().build().
      addTransportAddress(new InetSocketTransportAddress(
         InetAddress.getByName("localhost"), 9300));
      printResponse("getByName(\"localhost\")", client);
  
      client = TransportClient.builder().build().
      addTransportAddress(new InetSocketTransportAddress(
         InetAddress.getByAddress(new byte[] {127, 0, 0, 1}), 9300));
      printResponse("getByAddress(new byte[] {127, 0, 0, 1})", client);
   }

   private static void printResponse(String description, Client client) {
      try {
         GetResponse response = client.prepareGet("comicbook", "superhero", "1").get();
         System.out.println(description + ": " + response);
      } catch (NoNodeAvailableException e) {
         System.out.println(description + ": " + e);
      }
   }
}
```

Outputs this

```
getLocalHost: NoNodeAvailableException[None of the configured nodes are available: []]
getByName("localhost"): NoNodeAvailableException[None of the configured nodes are available: []]
getByAddress(new byte[] {127, 0, 0, 1}): NoNodeAvailableException[None of the configured nodes are available: []]
```

This

```
client = TransportClient.builder().build().
            addTransportAddress(new InetSocketTransportAddress("localhost", 9200));
```

which is valid according to [this question](http://stackoverflow.com/questions/16670219/why-cant-i-connect-to-elasticsearch-through-java-api), does not even compile.

My clustername is different, so I've also tried it with this at the top

```
Settings settings = Settings.settingsBuilder()
      .put("cluster.name", "clustername").build();
```

(and added `settings(settings)` to each builder), but same error.

What am I missing?

---

<div class="post-metadata">

**Author:** ![aliteralmind](https://avatars.discourse-cdn.com/v4/letter/a/c77e96/32.png) [@aliteralmind](https://discuss.elastic.co/u/aliteralmind)\
**Post date:** [November 12, 2015, 6:52pm UTC](https://discuss.elastic.co/t/elasticsearch-in-java-transportclient-nonodeavailableexception-none-of-the-configured-nodesare-available/34452/2 "2015-11-12T18:52:14Z")

</div>

Also posted here: [http://stackoverflow.com/questions/33677358/elasticsearch-in-java-transportclient-nonodeavailableexceptionnone-of-the-co](http://stackoverflow.com/questions/33677358/elasticsearch-in-java-transportclient-nonodeavailableexceptionnone-of-the-co)

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 12, 2015, 9:18pm UTC](https://discuss.elastic.co/t/elasticsearch-in-java-transportclient-nonodeavailableexception-none-of-the-configured-nodesare-available/34452/3 "2015-11-12T21:18:50Z")

</div>

I think your clustername is `myusername-elasticsearch-local`, right?

This is incorrect:

```auto
client = TransportClient.builder().build().
            addTransportAddress(new InetSocketTransportAddress("localhost", 9200));

```

Should be `9300` and the code does not compile with 2.0. You should write something like:

```auto
Settings settings = Settings.settingsBuilder()
      .put("cluster.name", clusterName).build();

Client client = TransportClient.builder().settings(settings).build()
      .addTransportAddress(new InetSocketTransportAddress(new InetSocketAddress("127.0.0.1", 9300)));

```

Actually this code is working for me.

---

<div class="post-metadata">

**Author:** ![aliteralmind](https://avatars.discourse-cdn.com/v4/letter/a/c77e96/32.png) [@aliteralmind](https://discuss.elastic.co/u/aliteralmind)\
**Post date:** [November 13, 2015, 2:59pm UTC](https://discuss.elastic.co/t/elasticsearch-in-java-transportclient-nonodeavailableexception-none-of-the-configured-nodesare-available/34452/4 "2015-11-13T14:59:21Z")

</div>

I was wondering if it was a version issue. Perhaps there's a version 2 of the book-tutorial that I've missed.

Unfortunately, that also gives me the same error 😞

I need to figure this out, and I'm unsure how to further diagnose it. I'm experienced with server side Java, but am new to ElasticSearch.

Thank you for your time, dadoonet.

---

<div class="post-metadata">

**Author:** ![aliteralmind](https://avatars.discourse-cdn.com/v4/letter/a/c77e96/32.png) [@aliteralmind](https://discuss.elastic.co/u/aliteralmind)\
**Post date:** [November 13, 2015, 5:01pm UTC](https://discuss.elastic.co/t/elasticsearch-in-java-transportclient-nonodeavailableexception-none-of-the-configured-nodesare-available/34452/5 "2015-11-13T17:01:00Z")

</div>

New code, which does exactly the same thing, but separates out the problem stuff better:

```
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.NoNodeAvailableException;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;

public class TrivialClient {

    public static void main(String[] args) throws UnknownHostException {
        InetSocketTransportAddress transportAddress = new InetSocketTransportAddress(
                InetAddress.getLocalHost(), 9300);
        createClientPrintResponse("getLocalHost", transportAddress);

        transportAddress = new InetSocketTransportAddress(
                        InetAddress.getByName("localhost"), 9300);

        createClientPrintResponse("getByName(\"localhost\")", transportAddress);

//Does not compile in ElasticSearch 2.0
// transportAddress = new InetSocketTransportAddress("localhost", 9200);
// createClientPrintResponse("getByName(\"localhost\")", transportAddress);

        transportAddress = new InetSocketTransportAddress(
                InetAddress.getByAddress(new byte[]{127, 0, 0, 1}), 9300);
        createClientPrintResponse("getByAddress(new byte[] {127, 0, 0, 1})", transportAddress);

        transportAddress =
                new InetSocketTransportAddress(new InetSocketAddress("127.0.0.1", 9300));
        createClientPrintResponse("InetSocketAddress", transportAddress);
    }

    private static void createClientPrintResponse(String description,
                                                  InetSocketTransportAddress transportAddress) {
        Settings settings = Settings.settingsBuilder()
                .put("cluster.name", "epsteinj-elasticsearch-local").build();
        Client client;
        client = TransportClient.builder().settings(settings).build().
                addTransportAddress(transportAddress);
        try {
            GetResponse response = client.prepareGet("comicbook", "superhero", "1").get();
            System.out.println(description + ": " + response);
        } catch (NoNodeAvailableException e) {
            System.out.println(description + ": " + e);
            //e.printStackTrace();
        }
    }
}
```

Output without stack traces:

```
getLocalHost: NoNodeAvailableException[None of the configured nodes are available: []]
getByName("localhost"): NoNodeAvailableException[None of the configured nodes are available: []]
getByAddress(new byte[] {127, 0, 0, 1}): NoNodeAvailableException[None of the configured nodes are available: []]
InetSocketAddress: NoNodeAvailableException[None of the configured nodes are available: []]
```

Stack trace:

```
NoNodeAvailableException[None of the configured nodes are available: []]
getLocalHost: 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.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:85)
    at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:59)
    at org.elasticsearch.action.ActionRequestBuilder.get(ActionRequestBuilder.java:67)
    at springes.esonly.TrivialClient.createClientPrintResponse(TrivialClient.java:47)
    at springes.esonly.TrivialClient.main(TrivialClient.java:19)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
```

---

<div class="post-metadata">

**Author:** ![rmswalsh1](https://avatars.discourse-cdn.com/v4/letter/r/e99b99/32.png) [@rmswalsh1](https://discuss.elastic.co/u/rmswalsh1)\
**Post date:** [December 13, 2015, 8:09pm UTC](https://discuss.elastic.co/t/elasticsearch-in-java-transportclient-nonodeavailableexception-none-of-the-configured-nodesare-available/34452/6 "2015-12-13T20:09:26Z")

</div>

Did you manage to solve this. I have read its an issue with the version?

---

<div class="post-metadata">

**Author:** ![rmswalsh1](https://avatars.discourse-cdn.com/v4/letter/r/e99b99/32.png) [@rmswalsh1](https://discuss.elastic.co/u/rmswalsh1)\
**Post date:** [December 13, 2015, 8:43pm UTC](https://discuss.elastic.co/t/elasticsearch-in-java-transportclient-nonodeavailableexception-none-of-the-configured-nodesare-available/34452/7 "2015-12-13T20:43:02Z")

</div>

I downloaded version 1.7.1 and the same code worked no problem.

---

<div class="post-metadata">

**Author:** ![tirupathi](https://avatars.discourse-cdn.com/v4/letter/t/ba9def/32.png) [@tirupathi](https://discuss.elastic.co/u/tirupathi)\
**Post date:** [February 24, 2016, 7:15pm UTC](https://discuss.elastic.co/t/elasticsearch-in-java-transportclient-nonodeavailableexception-none-of-the-configured-nodesare-available/34452/8 "2016-02-24T19:15:46Z")

</div>

> [@aliteralmind](#):
>
> telnet 127.0.0.1 9301

Is downgrading only the solution, I am looking for the solution "why we need to roll back to older version for such small issue"

---

<div class="post-metadata">

**Author:** ![Sathish\_Kandasamy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sathish_kandasamy/32/11043_2.png) [@Sathish\_Kandasamy](https://discuss.elastic.co/u/Sathish_Kandasamy)\
**Post date:** [July 25, 2016, 12:15am UTC](https://discuss.elastic.co/t/elasticsearch-in-java-transportclient-nonodeavailableexception-none-of-the-configured-nodesare-available/34452/9 "2016-07-25T00:15:16Z")

</div>

Thanks dadoonet. Your suggest code changes helped to resolve the problem.

---

<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, 10:33pm UTC](https://discuss.elastic.co/t/elasticsearch-in-java-transportclient-nonodeavailableexception-none-of-the-configured-nodesare-available/34452/10 "2017-07-05T22:33:18Z")

</div>


