NodeJS client unable to connect to Elasticsearch deployed in the same docker stack

I have a docker stack deployment inside which I have elastic search deployed as a service. Now I have another NodeJS application inside the same docker stack deployed as service. I am using the Official elastic search Client (@elastic/elasticsearch ) to make calls to Elastic from my node application. Now I am able to connect to elastic using Normal REST call like "http://elasticsearch:9200"
But the Client is not able to connect using this above URL.
const { Client } = require('@elastic/elasticsearch');
const client = new Client({ node: "http://elasticsearch:9200"});
Anyway to get this working?.

HEre is my elastic service defined in my stack yml file.

elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.4.2
environment:
- cluster.name=elastic-unifyed-cluster-stage
- bootstrap.memory_lock=false
- "ES_JAVA_OPTS=-Xms1024m -Xmx1024m"
- "xpack.security.enabled=false"
- "xpack.monitoring.enabled=false"
- "xpack.watcher.enabled=false"
- "network.host=0.0.0.0"
- "discovery.zen.ping.unicast.hosts=elasticsearch"
- "discovery.zen.minimum_master_nodes=3"
volumes:
- /apps/dockerdata/elastic:/usr/share/elasticsearch/data
deploy:
mode: global
endpoint_mode: dnsrr
restart_policy:
condition: on-failure
placement:
constraints: [node.labels.elastic == true]

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