Connecting to elastic cloud from elasticsearch.js

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

Please can some help me in solving this problem
Thank you

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.

  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!

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.

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.

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

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 you can set a log property on the client. Perhaps this'll help point in the right direction.

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

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

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

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