# Unable to Connect to ElasticSearch

**URL:** https://discuss.elastic.co/t/unable-to-connect-to-elasticsearch/321254
**Category:** Elasticsearch
**Tags:** docker, language-clients
**Created:** [December 15, 2022, 5:48am UTC](https://discuss.elastic.co/t/unable-to-connect-to-elasticsearch/321254 "2022-12-15T05:48:48Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![makarand](https://avatars.discourse-cdn.com/v4/letter/m/258eb7/32.png) [@makarand](https://discuss.elastic.co/u/makarand)
#### Post date: [December 15, 2022, 5:48am UTC](https://discuss.elastic.co/t/unable-to-connect-to-elasticsearch/321254/1 "2022-12-15T05:48:48Z")

</div>

> <https://github.com/localstack/localstack/issues/7326>
>
> \### Is there an existing issue for this?
> 
> \- \[X\] I have searched the existing iss…ues
> 
> \### Current Behavior
> 
> Trying to connect to elasticsearch domain using lambda and elasticsearch client but getting connection error.
> this is my docker-compose.yml file 
> \`\`\`
> version: "2.1"
> services:
> localstack:
> image: "localstack/localstack:latest"
> container\_name: "localstack"
> ports:
> - "4566-4620:4566-4620"
> - "127.0.0.1:8055:8080"
> environment:
> - DEBUG=1
> - EDGE\_PORT=4566
> - DATA\_DIR=/var/lib/localstack/data
> - DOCKER\_HOST=unix:///var/run/docker.sock
> - HOST\_TMP\_FOLDER=${TMPDIR}
> - LAMBDA\_EXECUTOR=docker
> - DYNAMODB\_SHARE\_DB=1
> - DISABLE\_CORS\_CHECKS=1
> - AWS\_DDB\_ENDPOINT=http://localhost:4566
> volumes:
> - "${TMPDIR:-/var/lib/localstack}:/var/lib/localstack"
> - "/var/run/docker.sock:/var/run/docker.sock"
> networks:
> - "local"
> 
>   
> networks:
> local:
> driver: "bridge"
>  
> \`\`\`
> 
> this is my elasticsearch client 
> \`\`\`
> const {Client} = require('@elastic/elasticsearch')
> module.exports.elasticClient = new Client({
> node : "http://localhost:4566"
> })
> \`\`\`
> 
> I'm trying to create index from client but connection is refused. 
> 
> \### Expected Behavior
> 
> It should create index using Client connector.
> 
> \### How are you starting LocalStack?
> 
> With a docker-compose file
> 
> \### Steps To Reproduce
> 
> \#### How are you starting localstack (e.g., \`bin/localstack\` command, arguments, or \`docker-compose.yml\`)
> 
> docker run localstack/localstack
> 
> \#### Client commands (e.g., AWS SDK code snippet, or sequence of "awslocal" commands)
> 
> awslocal s3 mb s3://mybucket
> 
> 
> \### Environment
> 
> \`\`\`markdown
> \- OS:windows 11
> \- LocalStack: 1.3.0
> \`\`\`
> 
> 
> \### Anything else?
> 
> \_No response\_

Hi guys can you please look into this? It is taking too much of my time.  
This is an error regarding connection from nodeJs client to Elasticsearch.

Trying to connect to elasticsearch domain using lambda and elasticsearch client but getting connection error.  
this is my docker-compose.yml file

```auto
version: "2.1"
services:
  localstack:
    image: "localstack/localstack:latest"
    container_name: "localstack"
    ports:
      - "4566-4620:4566-4620"
      - "127.0.0.1:8055:8080"
    environment:
      - DEBUG=1
      - EDGE_PORT=4566
      - DATA_DIR=/var/lib/localstack/data
      - DOCKER_HOST=unix:///var/run/docker.sock
      - HOST_TMP_FOLDER=${TMPDIR}
      - LAMBDA_EXECUTOR=docker
      - DYNAMODB_SHARE_DB=1
      - DISABLE_CORS_CHECKS=1
      - AWS_DDB_ENDPOINT=http://localhost:4566
    volumes:
      - "${TMPDIR:-/var/lib/localstack}:/var/lib/localstack"
      - "/var/run/docker.sock:/var/run/docker.sock"
    networks:
      - "local"

  
networks:
  local:
    driver: "bridge"
 

```

this is my elasticsearch client

```auto
const {Client} = require('@elastic/elasticsearch')
module.exports.elasticClient = new Client({
    node: 'http://mydomain.us-east-1.es.localhost.localstack.cloud:4566',
})

```

I'm trying to create index from client but connection is refused.

### Expected Behavior

It should create index using Client connector.

### Environment

- OS:windows 11 - LocalStack: 1.3.0

### Error I'm getting

```auto
lambda process returned with error. Result: {"errorType":"ConfigurationError","errorMessage":"Invalid protocol: 'mydomain.us-east-1.es.localhost.localstack.cloud:'"}. Output: 2022-12-14T13:11:45.942Z undefined ERROR Uncaught Exception {"errorType":"ConfigurationError","errorMessage":"Invalid protocol: 'mydomain.us-east-1.es.localhost.localstack.cloud:'","name":"ConfigurationError"

```

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [December 15, 2022, 5:50am UTC](https://discuss.elastic.co/t/unable-to-connect-to-elasticsearch/321254/2 "2022-12-15T05:50:12Z")

</div>

Welcome to our community! 😃 We aren't all guys here though.

It's not clear what that repo has to do with either Elasticsearch or nodejs sorry. If you have code and errors then it'd be great if you posted them directly here.

---

<div class="post-metadata">

### Author: ![makarand](https://avatars.discourse-cdn.com/v4/letter/m/258eb7/32.png) [@makarand](https://discuss.elastic.co/u/makarand)
#### Post date: [December 15, 2022, 5:51am UTC](https://discuss.elastic.co/t/unable-to-connect-to-elasticsearch/321254/3 "2022-12-15T05:51:39Z")

</div>

sure, i'll add the code as well

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [January 12, 2023, 5:52am UTC](https://discuss.elastic.co/t/unable-to-connect-to-elasticsearch/321254/4 "2023-01-12T05:52:21Z")

</div>

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