Unable to connect to Elastic Search nodes on Docker from Java

Hello,

I am not able to connect to Elasticsearch instance runned on docker via Java.
I use to run:
docker run -p 9200:9200 -p 9300:9300 -e "http.host=0.0.0.0" -e "transport.host=127.0.0.1" -e "xpack.security.enabled=false" docker.elastic.co/elasticsearch/elasticsearch:7.0.0

No error is shown. I am able to curl localhost:9300 and I get:
{ "name" : "9e2b50bda737", "cluster_name" : "docker-cluster", "cluster_uuid" : "JwdhJOQlRj-41WUC7ctdKQ", "version" : { "number" : "7.0.0", "build_flavor" : "default", "build_type" : "docker", "build_hash" : "b7e28a7", "build_date" : "2019-04-05T22:55:32.697037Z", "build_snapshot" : false, "lucene_version" : "8.0.0", "minimum_wire_compatibility_version" : "6.7.0", "minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know, for Search" }

But I am not able to connect from Java:
String clusterName = "docker-cluster"; Settings elasticsearchSettings = Settings.builder() .put("cluster.name", clusterName).build(); TransportClient client = new PreBuiltTransportClient(elasticsearchSettings); client.addTransportAddress(new TransportAddress(InetAddress.getByName("localhost"), 9300)); return client;

Any suggestion?

thank you
Francesco

You have transport host set to local host, while makes it inaccessible outside the container.

Thank you for the answer.

I am able to PUT docs in the instance via Postman also. Everything is working correctly besides from java. Could it be a firewall issue?
EDIT: I deactivated the firewall and it s still not working

How should I declare the transport.host?

Set it to the same as http.host. If you are just starting out I would however recommend you switch to the high-level rest client as the transport client is being deprecated.

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