Elasticsearch-5.0.0-beta1 JAVA APINoNodeAvailableException


(Venkatesh Kolisetty) #1

I downloaded Elasticsearch 5.0.0-beta1. I am trying to add documents through JAVA API.

I always get exception when trying to run.

Elasticsearch configuration

cluster.name: cluster_hostname
node.name: node_venkatesh
network.host : ${HOSTNAME}
http.port: 9500
transport.tcp.port: 9700
script.engine.groovy.inline.aggs: on
script.engine.groovy.inline.update: on

JAVA API Configuration

import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.client.Client;

Settings settings = null;
Client client = null;

this.settings = Settings.settingsBuilder()
				.put("cluster.name", "cluster_hostname")
				.put("client.transport.sniff", true)
				.put("node.name", "node_venkatesh")
				.put("transport.tcp.port", 9700).build();
this.client = TransportClient.builder().settings(settings).build().addTransportAddress(
			new InetSocketTransportAddress(InetAddress.getByName("HOSTNAME"), 9700));

Output when client is started

Sep 23, 2016 1:44:42 PM org.elasticsearch.plugins.PluginsService <init>
INFO: [node_venkatesh] modules [], plugins [], sites []
Sep 23, 2016 1:44:43 PM org.elasticsearch.client.transport.TransportClientNodesService$SniffNodesSampler$1$1 handleException
INFO: [node_venkatesh] failed to get local cluster state for {#transport#-1}{192.168.***.***}{HOSTNAME/192.168.***.***}, disconnecting...
NodeDisconnectedException[[][HOSTNAME/192.168.***.***:9700][cluster:monitor/state] disconnected]

Exception while running code

Exception in thread "main" NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{192.168.***.***}{HOSTNAME/192.168.***.***:9700}]]
    at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:290)
    at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:207)
    at org.elasticsearch.client.transport.support.TransportProxyClient.execute(TransportProxyClient.java:55)
    at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:288)
    at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:359)
    at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:86)
    at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:56)
    at org.elasticsearch.action.ActionRequestBuilder.get(ActionRequestBuilder.java:64)

This configuration and code is perfectly working with elasticsearch-2.3.3 .

Kindly help.


(Daniel Mitterdorfer) #2

Hi @VenkateshK,

it seems you did not update the client, because the API has changed in 5.0.

This should get you going:

package org.elasticsearch.client.example;

import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;

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

public class Scratch {
    public static void main(String[] args) throws UnknownHostException {
        Settings settings = Settings.builder()
            .put("cluster.name", "your_cluster_name_here")
            .put("client.transport.sniff", true)
            .put("node.name", "sample_client_node")
            .put("transport.tcp.port", 9700).build();
        TransportClient client = new PreBuiltTransportClient(settings);
        client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("your_cluster_ip_here"), 9700));

        final ClusterHealthResponse res = client.admin().cluster().health(new ClusterHealthRequest()).actionGet();
        System.out.println(res.getClusterName());
    }
}

Daniel


(Avneesh Atri) #3

Hi @danielmitterdorfer ,
Thanks for the sample code . I am trying your sample code with elasticsearch 5.0.0-beta1 version and I have following dependency included in my project . But it looks like this jar does not contain class org.elasticsearch.transport.client.PreBuiltTransportClient .
Seems like jar present in maven is not up to date . Can you please point to the correct source from where I can download the jar for Elasticsearch-5.0.0-beat1 version.

<dependency> <groupId>org.elasticsearch</groupId> <artifactId>elasticsearch</artifactId> <version>5.0.0-beta1</version> </dependency>


(David Pilato) #4

Client ArtifactId changed. Read https://www.elastic.co/guide/en/elasticsearch/client/java-api/5.0/_maven_repository.html


(Avneesh Atri) #5

Thanks, got it working


(wlxwolves) #6

Hi, @danielmitterdorfer
I don't understand what what should I set "node.name". Can I set any string to node.name or a specific name of node in ES cluster?

 .put("node.name", "sample_client_node")

Thanks .


(Daniel Mitterdorfer) #7

Hi @wlxwolves,

this setting defines the "node" name of your transport client. You can set it to any value. However, you don't need to specify this setting necessarily. I just included it in my answer as it was also included in the question.

Daniel


(system) #8