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.

- bootstrap.memory_lock=false
- "ES_JAVA_OPTS=-Xms1024m -Xmx1024m"
- ""
- "xpack.monitoring.enabled=false"
- "xpack.watcher.enabled=false"
- ""
- ""
- "discovery.zen.minimum_master_nodes=3"
- /apps/dockerdata/elastic:/usr/share/elasticsearch/data
mode: global
endpoint_mode: dnsrr
condition: on-failure
constraints: [node.labels.elastic == true]

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