hello_its_me
hello_its_me

Reputation: 793

NoNode Error when trying to create a transport client for Elasticsearch

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.

Upvotes: 1

Views: 684

Answers (1)

hello_its_me
hello_its_me

Reputation: 793

Apparently I should run it on port 9300, not 9200:

.addTransportAddress(new InetSocketTransportAddress(InetAddress.getLocalHost(), 9300))
                .addTransportAddress(new InetSocketTransportAddress(InetAddress.getLocalHost(), 9300)))

Upvotes: 1

Related Questions