Java client: Unable to connect to elastic cloud instance

Hi,
I am trying to use Java Client to connect to my elastic.co cloud instance. Here is my code, I am getting NoNodeAvailableException. Let me know if I am missing some thing. Appreciate any help.
Code:

try {
// Elastic Endpoint: https://3bc1590ea5e7ea7fcb7adc416f951b59.us-east-1.aws.found.io:9243

		String clusterName= "autospecs-drawings-dev";
		String esHost = "3bc1590ea5e7ea7fcb7adc416f951b59.us-east-1.aws.found.io";
		int esPort = 9243;
		this.transportAddress = new InetSocketTransportAddress(InetAddress.getByName(esHost), esPort);

		Settings settings = Settings.builder()
				.put("cluster.name", clusterName).
				put("logger.org.elasticsearch.transport.TransportService.tracer", "TRACE").
				build();

		this.client = new PreBuiltTransportClient(settings).addTransportAddress(transportAddress);
		SearchResponse sr = client.prepareSearch("autospecs-drawings-0").get();
		long numHits = sr.getHits().getTotalHits();
		System.out.println("Number of hits is " + numHits);

	} catch (Exception e) {
		//e.printStackTrace();
		// TODO Auto-generated catch block
		esLogger.error("Exception during getting transportAddress", e);
	}

Exception is this.
15:55:13.640 [main] ERROR - Exception during getting transportAddress
org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: [{#transport#-1}{1NmEyI9ySICMCg-AuluqMA}{3bc1590ea5e7ea7fcb7adc416f951b59.us-east-1.aws.found.io}{54.197.250.163:9243}]
at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:347) ~[elasticsearch-5.5.0.jar:5.5.0]
at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:245) ~[elasticsearch-5.5.0.jar:5.5.0]
at org.elasticsearch.client.transport.TransportProxyClient.execute(TransportProxyClient.java:59) ~[elasticsearch-5.5.0.jar:5.5.0]
at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:363) ~[elasticsearch-5.5.0.jar:5.5.0]
at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:408) ~[elasticsearch-5.5.0.jar:5.5.0]
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:80) ~[elasticsearch-5.5.0.jar:5.5.0]
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:54) ~[elasticsearch-5.5.0.jar:5.5.0]
at org.elasticsearch.action.ActionRequestBuilder.get(ActionRequestBuilder.java:62) ~[elasticsearch-5.5.0.jar:5.5.0]
at com.pype.autospecs.util.ESUtil.(ESUtil.java:61) [bin/:?]
at com.pype.autospecs.util.ESUtil.(ESUtil.java:28) [bin/:?]

Try port 9343 instead.

I tried, but no luck. I get the same exception. Should I give username/password (elastic/) which cloud.elastic.co has given me during sign up some where??

Hare is an example from the docs: https://www.elastic.co/guide/en/cloud/current/security.html#security-transport

Hi Christian,
It looks too complicated to take that code. Also, shield is part of XPack as I have read some where. Would anyone have a readymade Java client code that connects/queries the elastic cloud node?

What about it is too complicated? It shows the headings and settings that need to be set in order to be able to connect to Elastic Cloud.

Hello Christian,
I am using 5.x client. When I use shield.user it says, unknown setting. On the other hand, if I use xpack.security.user, its giving same error.

So, for 5.5 client, what is the setting property for given user name and password. I am able to connect using Curl command by giving -u option with username:passwd

Just realised that the example in the docs is for ES 2.x. There is however also a link to a 5.x example available on the page which it looks like you have found: https://github.com/elastic/found-shield-example/blob/5.x/src/main/java/org/elasticsearch/cloud/transport/example/TransportExample.java

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