# Connecting to elastic cloud from elasticsearch.js

**URL:** https://discuss.elastic.co/t/connecting-to-elastic-cloud-from-elasticsearch-js/157963
**Category:** Elasticsearch
**Created:** [November 23, 2018, 6:25am UTC](https://discuss.elastic.co/t/connecting-to-elastic-cloud-from-elasticsearch-js/157963 "2018-11-23T06:25:59Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Sai\_Krishna](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@Sai\_Krishna](https://discuss.elastic.co/u/Sai_Krishna)
#### Post date: [November 23, 2018, 6:26am UTC](https://discuss.elastic.co/t/connecting-to-elastic-cloud-from-elasticsearch-js/157963/1 "2018-11-23T06:26:00Z")

</div>

I deployed my cluster on the elastic cloud.  
All these days before deplyoing I worked on it locally **ex** : host: 'localhost:9200'  
platform I use is **Node js (elasticsearch.js) package.**

But now whenever I am trying to make a **connection with elastic cloud** I keep getting an error.

[code](https://pastebin.com/3QW2LfZ1)

Please can some help me in solving this problem  
Thank you

---

<div class="post-metadata">

### Author: ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)
#### Post date: [November 23, 2018, 9:56am UTC](https://discuss.elastic.co/t/connecting-to-elastic-cloud-from-elasticsearch-js/157963/2 "2018-11-23T09:56:21Z")

</div>

```auto
ERROR: 2018-11-23T05:33:01Z
  Error: Request error, retrying
  HEAD http://localhost:9200/ => connect ECONNREFUSED 127.0.0.1:9200

```

This indicates you are still trying to connect to a local Elasticsearch, which is no longer running.

```auto
  const esClient = new elasticsearch.Client({
    hosts: [
    // 'https://elastic:REDACTED@REDACTED.ap-southeast-1.aws.found.io:9243/']
    });
  return esClient;
};

```

Is it that the host name is commented out?

Also you just shared your cluster id, username and password with the world. Please change them ASAP!

---

<div class="post-metadata">

### Author: ![Sai\_Krishna](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@Sai\_Krishna](https://discuss.elastic.co/u/Sai_Krishna)
#### Post date: [November 23, 2018, 10:17am UTC](https://discuss.elastic.co/t/connecting-to-elastic-cloud-from-elasticsearch-js/157963/3 "2018-11-23T10:17:59Z")

</div>

Sorry i totally forgot about my details being shown.(changed them now). Thanks for that.

i did not comment that host name.i cross checked it, still it gives the same error  
.  
This is only place where i did configuration.

---

<div class="post-metadata">

### Author: ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)
#### Post date: [November 23, 2018, 4:31pm UTC](https://discuss.elastic.co/t/connecting-to-elastic-cloud-from-elasticsearch-js/157963/4 "2018-11-23T16:31:31Z")

</div>

The line was commented-out the line in the code that you shared, and connecting to localhost is the default, so this error is at least consistent with commenting that line out.

Could you share the code that you're using here, without any commenting, but redacting your cluster ID and password **and making no further changes**? You can format code neatly using the `</>` formatting button.

---

<div class="post-metadata">

### Author: ![Sai\_Krishna](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@Sai\_Krishna](https://discuss.elastic.co/u/Sai_Krishna)
#### Post date: [November 24, 2018, 5:10am UTC](https://discuss.elastic.co/t/connecting-to-elastic-cloud-from-elasticsearch-js/157963/5 "2018-11-24T05:10:13Z")

</div>

Hi David Turner,  
The code which I used for **connecting**  **elasticsearch** is

```
    const getElasticClient = () => {
  const esClient = new elasticsearch.Client({
    host:
      'https://user:passwd@cluster_id.ap-southeast-1.aws.found.io:9243/'
  });
  return esClient;

```

};

and I call this method whenever I start the backend.

elasticsearch\_settings is the file name where the above method has been written.

```
const es = require('./elasticsearch_settings');

es.getElasticClient;

```

Still it always gives error of **localhost connection**

---

<div class="post-metadata">

### Author: ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)
#### Post date: [November 24, 2018, 11:10pm UTC](https://discuss.elastic.co/t/connecting-to-elastic-cloud-from-elasticsearch-js/157963/6 "2018-11-24T23:10:46Z")

</div>

I'm sorry, I'm not enough of a Javascript expert to guess where in your plumbing the settings are getting lost. I tried putting those two snippets into files and running them with `node` and they seem to be missing pieces. I cannot reproduce what you're seeing with the information you've given so far. Can you share a minimal, but complete and self-contained, example that I can run myself?

I note that [according to this page](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/quick-start.html#_creating_a_client) you can set a `log` property on the client. Perhaps this'll help point in the right direction.

---

<div class="post-metadata">

### Author: ![Sai\_Krishna](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@Sai\_Krishna](https://discuss.elastic.co/u/Sai_Krishna)
#### Post date: [November 28, 2018, 11:33am UTC](https://discuss.elastic.co/t/connecting-to-elastic-cloud-from-elasticsearch-js/157963/7 "2018-11-28T11:33:53Z")

</div>

Hi David Turner  
I completely erased all the elasticsearch settings.  
cloned the project again and now added elasticsearch configurations.It connected successfully.  
But now whenever i am indexing anything into it.  
it gives this error.

```
 <- 404
  {
    "ok": false,
    "message": "Unknown cluster."
  }

```

Thank you

---

<div class="post-metadata">

### Author: ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)
#### Post date: [November 28, 2018, 1:11pm UTC](https://discuss.elastic.co/t/connecting-to-elastic-cloud-from-elasticsearch-js/157963/8 "2018-11-28T13:11:18Z")

</div>

I think this message comes from Elastic Cloud and suggests you are not using the correct cluster ID.

---

<div class="post-metadata">

### Author: ![Sai\_Krishna](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@Sai\_Krishna](https://discuss.elastic.co/u/Sai_Krishna)
#### Post date: [November 29, 2018, 6:56am UTC](https://discuss.elastic.co/t/connecting-to-elastic-cloud-from-elasticsearch-js/157963/9 "2018-11-29T06:56:05Z")

</div>

Can you suggest where to use cluster ID.  
Thank you.

---

<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: [December 27, 2018, 6:56am UTC](https://discuss.elastic.co/t/connecting-to-elastic-cloud-from-elasticsearch-js/157963/10 "2018-12-27T06:56:07Z")

</div>

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