# NoNodeException Error when trying to create a transport client for Elasticsearch

**URL:** <https://discuss.elastic.co/t/nonodeexception-error-when-trying-to-create-a-transport-client-for-elasticsearch/37067>\
**Category:** Elasticsearch\
**Created:** [December 13, 2015, 4:47pm UTC](https://discuss.elastic.co/t/nonodeexception-error-when-trying-to-create-a-transport-client-for-elasticsearch/37067 "2015-12-13T16:47:24Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Isra](https://avatars.discourse-cdn.com/v4/letter/i/7ba0ec/32.png) [@Isra](https://discuss.elastic.co/u/Isra)\
**Post date:** [December 13, 2015, 4:47pm UTC](https://discuss.elastic.co/t/nonodeexception-error-when-trying-to-create-a-transport-client-for-elasticsearch/37067/1 "2015-12-13T16:47:24Z")

</div>

I am running Elasticsearch 2.1.0 on localhost:9200. What I need to do is read from an index using Java for ES, without having to create a node, because I care about the speed of my application. The following is my code:

```
try (Client client = TransportClient.builder().build()
                .addTransportAddress(new InetSocketTransportAddress(InetAddress.getLocalHost(), 9200))
                .addTransportAddress(new InetSocketTransportAddress(InetAddress.getLocalHost(), 9200))) {
            QueryBuilder qb = matchQuery(
                    ...
            );  
            CountResponse response;
            response = client.prepareCount(indexName)
                    .setTypes(spammerType).setQuery(qb)
                    .execute()
                    .actionGet();
        }

```

However, I am getting the following error:

```
Exception in thread "main" NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{127.0.0.1}{localhost/127.0.0.1:9200}]]

```

But I'm trying to avoid creating a node because as I mentioned before, I need my application to be as fast as possible in reading from the index. According to ES:

> There are uses-cases for both clients:
> 
> The transport client is ideal if you want to decouple your application  
> from the cluster. For example, if your application quickly creates and  
> destroys connections to the cluster, a transport client is much  
> "lighter" than a node client, since it is not part of a cluster.
> 
> Similarly, if you need to create thousands of connections, you don’t  
> want to have thousands of node clients join the cluster. The TC will  
> be a better choice.
> 
> On the flipside, if you need only a few long-lived, persistent  
> connection objects to the cluster, a node client can be a bit more  
> efficient since it knows the cluster layout. But it ties your  
> application into the cluster, so it may pose problems from a firewall  
> perspective.

How can I fix the error?? Thanks.

---

<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:** [December 13, 2015, 5:26pm UTC](https://discuss.elastic.co/t/nonodeexception-error-when-trying-to-create-a-transport-client-for-elasticsearch/37067/2 "2015-12-13T17:26:07Z")

</div>

Use port 9300 instead.

---

<div class="post-metadata">

**Author:** ![Isra](https://avatars.discourse-cdn.com/v4/letter/i/7ba0ec/32.png) [@Isra](https://discuss.elastic.co/u/Isra)\
**Post date:** [December 14, 2015, 6:43am UTC](https://discuss.elastic.co/t/nonodeexception-error-when-trying-to-create-a-transport-client-for-elasticsearch/37067/3 "2015-12-14T06:43:46Z")

</div>

Can I perform a search query using the transport client? Because when I tried port 9300 without the search query, it finally returned no errors (thank you). However, when I added my search query and wanted the result to be returned, I got the `NoNodeException`error again.

---

<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:** [December 14, 2015, 6:58am UTC](https://discuss.elastic.co/t/nonodeexception-error-when-trying-to-create-a-transport-client-for-elasticsearch/37067/4 "2015-12-14T06:58:17Z")

</div>

Of course you can. Look at the Java guide: [https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-search.html](https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-search.html)

---

<div class="post-metadata">

**Author:** ![Isra](https://avatars.discourse-cdn.com/v4/letter/i/7ba0ec/32.png) [@Isra](https://discuss.elastic.co/u/Isra)\
**Post date:** [December 14, 2015, 7:41am UTC](https://discuss.elastic.co/t/nonodeexception-error-when-trying-to-create-a-transport-client-for-elasticsearch/37067/5 "2015-12-14T07:41:55Z")

</div>

Okay, but the following is my search and yet I am receiving the NoNode error:

```
try (Client client = TransportClient.builder().build()
        .addTransportAddress(new InetSocketTransportAddress(InetAddress.getLocalHost(), 9300))
        .addTransportAddress(new InetSocketTransportAddress(InetAddress.getLocalHost(), 9300))) {
    QueryBuilder qb = matchQuery(
            "user_name",
            Username
    );  
    
    CountResponse response = client.prepareCount(indexName)
            .setTypes(spammerType).setQuery(qb)
            .execute()
            .actionGet();
    return response;
}

```

And the following is the error I am receiving.

`Exception in thread "main" NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{ **.**. **.** }{ ***/**. **.**.**:9300}]]`

When I tried the same query for the node client, it worked for me with no errors. Why is it now showing me that error?

Thanks.

---

<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:** [December 14, 2015, 8:53am UTC](https://discuss.elastic.co/t/nonodeexception-error-when-trying-to-create-a-transport-client-for-elasticsearch/37067/6 "2015-12-14T08:53:49Z")

</div>

Hard to say. First guess: cluster name?  
Second guess: network.host not properly set in your node?

---

<div class="post-metadata">

**Author:** ![Isra](https://avatars.discourse-cdn.com/v4/letter/i/7ba0ec/32.png) [@Isra](https://discuss.elastic.co/u/Isra)\
**Post date:** [December 14, 2015, 8:58am UTC](https://discuss.elastic.co/t/nonodeexception-error-when-trying-to-create-a-transport-client-for-elasticsearch/37067/7 "2015-12-14T08:58:26Z")

</div>

I've removed the comment of the [cluster.name](http://cluster.name) in my elasticsearch.yml configuration file and set it to "elasticsearch". Then, I added the following to my application:

```
Settings.Builder st = Settings.builder()
                .put("cluster.name", "elasticsearch");

try (Client client = TransportClient.builder().settings(st).build()
        .addTransportAddress(new InetSocketTransportAddress(InetAddress.getLocalHost(), 9300)))

```

But I am still receiving the same error. How can I fix the network.host if it was indeed the problem?? I'm running ES on localhost:9200 and the configurations of that in the elasticsearch.yml are all commented out.

---

<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:** [December 15, 2015, 8:29am UTC](https://discuss.elastic.co/t/nonodeexception-error-when-trying-to-create-a-transport-client-for-elasticsearch/37067/8 "2015-12-15T08:29:26Z")

</div>

This? [https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html)

Define it to your ip address for example.

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [December 15, 2015, 8:59am UTC](https://discuss.elastic.co/t/nonodeexception-error-when-trying-to-create-a-transport-client-for-elasticsearch/37067/9 "2015-12-15T08:59:22Z")

</div>

You use `InetAddress.getLocalHost()`, this may return an IPv6 address. Is Elasticsearch configured for IPv6?

In the message `Exception in thread "main" NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{ **.**. **.** }{ ***/**. **.**.**:9300}]]` you can see the correct IP and Elasticsearch must be configured to this IP.

---

<div class="post-metadata">

**Author:** ![Isra](https://avatars.discourse-cdn.com/v4/letter/i/7ba0ec/32.png) [@Isra](https://discuss.elastic.co/u/Isra)\
**Post date:** [December 15, 2015, 9:10am UTC](https://discuss.elastic.co/t/nonodeexception-error-when-trying-to-create-a-transport-client-for-elasticsearch/37067/10 "2015-12-15T09:10:48Z")

</div>

OKay, I got it to work. I defined the network.host in the ES configs to localhost and only then it worked. thanks.

---

<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:31pm UTC](https://discuss.elastic.co/t/nonodeexception-error-when-trying-to-create-a-transport-client-for-elasticsearch/37067/11 "2017-07-05T23:31:00Z")

</div>


