# I'm facing "NoNodeAvailableException" but doesn't now what I'm doing wrong!

**URL:** <https://discuss.elastic.co/t/im-facing-nonodeavailableexception-but-doesnt-now-what-im-doing-wrong/102806>\
**Category:** Elasticsearch\
**Created:** [October 5, 2017, 7:50am UTC](https://discuss.elastic.co/t/im-facing-nonodeavailableexception-but-doesnt-now-what-im-doing-wrong/102806 "2017-10-05T07:50:31Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![sebF](https://avatars.discourse-cdn.com/v4/letter/s/8491ac/32.png) [@sebF](https://discuss.elastic.co/u/sebF)\
**Post date:** [October 5, 2017, 7:50am UTC](https://discuss.elastic.co/t/im-facing-nonodeavailableexception-but-doesnt-now-what-im-doing-wrong/102806/1 "2017-10-05T07:50:31Z")

</div>

Hi

I create new topic because I did not find a solution to my pb in the other threads.

My pb is that I face the following error when I try to perform a search query on elasticsearch thanks a java client:

```auto
InetSocketAddress: NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{mqrDOkH-Sbu4haRYxMekXg}{xxx.xxx.xxx.xxx}{xxx.xxx.xxx.xxx:9300}]]

```

Here is a curl where I can see my cluster informations:

```
curl -XGET 'xxx.xxx.xxx.xxx/'
{
  "name" : "my-node-name-1",
  "cluster_name" : "my-cluster-name",
  "cluster_uuid" : "lmhoyPBWQTu2SSt-3BabRg",
  "version" : {
    "number" : "5.4.0",
    "build_hash" : "780f8c4",
    "build_date" : "2017-04-28T17:43:27.229Z",
    "build_snapshot" : false,
    "lucene_version" : "6.5.0"
  },
  "tagline" : "You Know, for Search"
}

```

I think I have the right versions for the librairies I use to connect, here is my pom:

```
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>test.elasticsearch</groupId>
    <artifactId>TestElasticSearch</artifactId>
    <version>1.0-SNAPSHOT</version>

    <packaging>jar</packaging>

    <name>transaction-generator</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.9</version>
            <scope>test</scope>
        </dependency>
		<dependency>
			<groupId>org.elasticsearch.client</groupId>
			<artifactId>transport</artifactId>
			<version>5.4.0</version>
		</dependency>
		     <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>2.7</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.7</version>
        </dependency>        
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

```

And I'm using this class I found on this forum:

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

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

public class TrivialClient {

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

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

    private static void createClientPrintResponse(String description,
            InetSocketTransportAddress transportAddress) {
        System.out.println("begining : " + description + "... ");

        Settings settings = Settings.builder()
                .put("cluster.name", "my-cluster-name").build();
        Client client;
        client = new PreBuiltTransportClient(settings).
                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();
        }
    }
}

```

Does somebody now what I'm doing wrong? Or what I miss?

---

<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:** [October 5, 2017, 8:11am UTC](https://discuss.elastic.co/t/im-facing-nonodeavailableexception-but-doesnt-now-what-im-doing-wrong/102806/2 "2017-10-05T08:11:46Z")

</div>

Please format your code using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will make your post more readable.

Or use markdown style like:

````
```
CODE
```

````

I edited your post.

What are the elasticsearch server full logs please?  
Are you running the java app from the same machine where elasticsearch is hosted?

---

<div class="post-metadata">

**Author:** ![sebF](https://avatars.discourse-cdn.com/v4/letter/s/8491ac/32.png) [@sebF](https://discuss.elastic.co/u/sebF)\
**Post date:** [October 5, 2017, 8:48am UTC](https://discuss.elastic.co/t/im-facing-nonodeavailableexception-but-doesnt-now-what-im-doing-wrong/102806/3 "2017-10-05T08:48:38Z")

</div>

Sorry for the malformed post!

I'm running my code from my machine and the elasticsearch is hosted on another machine.  
But the curl I posted works fine from my machine.

For the moment, we do not see anything in the logs on the elasticsearch host (nor on the other nodes of the cluster.)

Here is the /etc/elasticsearch/elasticsearch.yml file of the concerned machine.

```auto
cluster.name: my-cluster-name
node.name: my-node-name-1
path.conf: /etc/elasticsearch
plugin.mandatory: discovery-ec2
discovery.type: ec2
discovery.ec2.groups: SG-PROD-LOGGING-ELASTICSEARCH-RTB
discovery.ec2.host_type: private_ip
cloud.aws.region: us-east
http.enabled: true
http.port: 9200
transport.tcp.port: 9300
bootstrap.memory_lock: true
node.master: false
node.data: false
node.ingest: false
network.host: xxx.xxx.xxx.xxx
discovery.ec2.tag.escluster: nv-rtb5
discovery.zen.minimum_master_nodes: 2
search.default_search_timeout: 30s
indices.fielddata.cache.size: 40%

```

Note that ip "[xxx.xxx.xxx.xxx](http://xxx.xxx.xxx.xxx)" in the elasticsearch.yml, in the TrivialClient.java and in the curl is the same

---

<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:** [October 5, 2017, 9:05am UTC](https://discuss.elastic.co/t/im-facing-nonodeavailableexception-but-doesnt-now-what-im-doing-wrong/102806/4 "2017-10-05T09:05:24Z")

</div>

So `network.host` has the public IP address, right?

Everything looks good.

I wonder if you opened the 9300 port in AWS?

BTW I think it's a bad idea exposing your elasticsearch on internet.  
At least you should add X-Pack (commercial) to protect it.

(Or consider [cloud.elastic.co](http://cloud.elastic.co) which has all that built-in and managed).

---

<div class="post-metadata">

**Author:** ![sebF](https://avatars.discourse-cdn.com/v4/letter/s/8491ac/32.png) [@sebF](https://discuss.elastic.co/u/sebF)\
**Post date:** [October 5, 2017, 9:24am UTC](https://discuss.elastic.co/t/im-facing-nonodeavailableexception-but-doesnt-now-what-im-doing-wrong/102806/5 "2017-10-05T09:24:08Z")

</div>

Thanks a lot!!!!

We've found the issue with your helping questions!  
It was related to the opened port (so obvious... ☹ )

We do not use public Ip and are hosted and the elasticsearch we use are not reachable outside our VPN.

That makes me wonder why we need to connect to the 9300 port (that seems to be the port used by the cluster itself) with the java client while I wanted to perform a search query on the 9200 port (like I do with my curl)?

---

<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:** [October 5, 2017, 9:37am UTC](https://discuss.elastic.co/t/im-facing-nonodeavailableexception-but-doesnt-now-what-im-doing-wrong/102806/6 "2017-10-05T09:37:33Z")

</div>

Use the Java REST client instead.

---

<div class="post-metadata">

**Author:** ![sebF](https://avatars.discourse-cdn.com/v4/letter/s/8491ac/32.png) [@sebF](https://discuss.elastic.co/u/sebF)\
**Post date:** [October 5, 2017, 10:09am UTC](https://discuss.elastic.co/t/im-facing-nonodeavailableexception-but-doesnt-now-what-im-doing-wrong/102806/7 "2017-10-05T10:09:39Z")

</div>

Ho, much better!  
That was the solution I looked for!

Thanks David!

Maybe you know a good/easy library to parse the response and store it as csv?

---

<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:** [October 5, 2017, 10:23am UTC](https://discuss.elastic.co/t/im-facing-nonodeavailableexception-but-doesnt-now-what-im-doing-wrong/102806/8 "2017-10-05T10:23:52Z")

</div>

> parse the response

The High Level Rest Client can parse the response.  
Otherwise you can use Jackson to read the response stream and parse it as a Map or whatever.

> store it as csv

Not a library as per say but Logstash can do that.

---

<div class="post-metadata">

**Author:** ![sebF](https://avatars.discourse-cdn.com/v4/letter/s/8491ac/32.png) [@sebF](https://discuss.elastic.co/u/sebF)\
**Post date:** [October 5, 2017, 1:19pm UTC](https://discuss.elastic.co/t/im-facing-nonodeavailableexception-but-doesnt-now-what-im-doing-wrong/102806/9 "2017-10-05T13:19:34Z")

</div>

Thanks David.

The HighLevel Rest Client does what I did myself (in a better way).  
The remaining thing I need to do is loading my query from a file (I'm looking into Script for that).

Regarding the csv, my goal, is not exactly to generate a csv file, but to save data "row by row" in a redshift like I can see in some kibana visualization. I'll look what I can do.

---

<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:** [October 5, 2017, 1:31pm UTC](https://discuss.elastic.co/t/im-facing-nonodeavailableexception-but-doesnt-now-what-im-doing-wrong/102806/10 "2017-10-05T13:31:59Z")

</div>

Have a look at the scroll API if your intention is to extract a lot of data.

---

<div class="post-metadata">

**Author:** ![sebF](https://avatars.discourse-cdn.com/v4/letter/s/8491ac/32.png) [@sebF](https://discuss.elastic.co/u/sebF)\
**Post date:** [October 6, 2017, 7:29am UTC](https://discuss.elastic.co/t/im-facing-nonodeavailableexception-but-doesnt-now-what-im-doing-wrong/102806/11 "2017-10-06T07:29:03Z")

</div>

Thanks for the advice.  
i'll take a look at this

---

<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:** [November 3, 2017, 7:29am UTC](https://discuss.elastic.co/t/im-facing-nonodeavailableexception-but-doesnt-now-what-im-doing-wrong/102806/12 "2017-11-03T07:29:10Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
