I am trying to connect to a remote elastic search cluster using Transport client.
public class AuthenticationExample {
public static void main(String[] args) throws Exception {
if (args.length != 4) {
System.out.println("Usage :\njava -jar jarFile.jar clusterName hostIP port index");
System.exit(0);
}
String clusterName = args[0];
String hostName = args[1];
int port = Integer.parseInt(args[2]);
String index = args[3];
Settings settings = Settings.builder()
.put("cluster.name", clusterName).build();
TransportClient esClient = new PreBuiltTransportClient(settings)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostName), port));
esClient.threadPool().getThreadContext().putHeader("Authorization", "Basic " + Base64.encodeBase64("user:password".getBytes()));
System.out.println("Initialized successfully.");
boolean isIndexExists = false;
isIndexExists = esClient.admin().indices().prepareExists(index).execute().actionGet().isExists();
if (isIndexExists) {
System.out.println("Is Index " + index + " Exists? " + isIndexExists);
} else {
System.out.println("Index " + index + " does not exist");
}
}
}
When I run the above code, as
java -jar jarFile.jar clusterName XXX.XXX.XXX.XXX 9300 indexName
I am getting the following exception NoNodeAvailableException[None of the configured nodes are available: ...
Also when I hit the endpoint using,
curl -XGET -u user:password http://XXX.XXX.XXX.XXX:9200
I am getting the response as follows,
{
"name" : "XfJq4ed",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "26yoM76iT8i-eo8k0E8y4g",
"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"
}
Kindly give me a solution. Thanks