Hi , I have issue connecting to elasticsearch in Docker container using Elasticsearch Transport Client.
If I curl to elasticsearch from terminal, it seems fine:
$ curl -XGET http://elasticsearch:9200/_nodes/http?pretty=1
{
"_nodes" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"cluster_name" : "es-cluster",
"nodes" : {
"NGQR55QPTyilP9kRxpT_1Q" : {
"name" : "NGQR55Q",
"transport_address" : "127.0.0.1:9300",
"host" : "127.0.0.1",
"ip" : "127.0.0.1",
"version" : "5.5.0",
"build_hash" : "260387d",
"roles" : [
"master",
"data",
"ingest"
],
"http" : {
"bound_address" : [
"[::]:9200"
],
"publish_address" : "172.30.254.8:9200",
"max_content_length_in_bytes" : 104857600
}
}
}
}
And then I use transport client in Java program,
final String clusterName = "es-cluster";
final String hostName = "elasticsearch";
final int port = 9200;
final Settings settings = Settings.builder().put("cluster.name", clusterName).put("client.transport.sniff", false).build();
TransportClient client = new PreBuiltTransportClient(settings);
client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostName), port);
But when I tried to index a document, I got an exception saying no configured nodes are available.
What confuses me is what address(or host name) and port number I should use to connect to elastic in Docker. The ES version is 5.5.0.
Any help would be very much appreciated!!!
UPDATE
I solved the problem eventually.
By default the network ip for transport is 127.0.0.1 rather than 0.0.0.0. Because it’s only listening to 127.0.0.1 rahter than all interfaces, when accessing from outside the container, the transport is not accessible. So I set it to 0.0.0.0.
The problem following this is reseting the ip address triggers the bootstrap checks, which fail due to map counts check. Running “sysctl -w vm.max_map_count=262144” solves the problem.