0

I wanted to check if elasticsearch.js was connected to the internet.

So I ran client.ping in my production environment as follows.

client.ping({
  requestTimeout: 30000,
}, function (error) {
  if (error) {
    console.error('elasticsearch cluster is down!');
  } else {
    console.log('All is well');
  }
});

I received an error log saying "elasticsearch cluster is down!".

On the other hand, when I run client.ping in my development environment on my own machine, I received a log saying "All is well".

curl command works on terminal in the production environment.

For example, the following curl command works.

curl -XPOST 'http://172.31.18.8:9200/users/_search?pretty' -H 'Content-Type: application/json' -d'
{
  "suggest" : {
    "docsuggest" : {
      "text" : "m",
      "completion" : {
        "field" : "name_suggest",
        "fuzzy": true
      }
    }
  }
}'
{
  "took" : 10,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "failed" : 0
  },
  "hits" : {
    "total" : 0,
    "max_score" : 0.0,
    "hits" : [ ]
  },
  "suggest" : {
    "docsuggest" : [
      {
        "text" : "m",
        "offset" : 0,
        "length" : 1,
        "options" : [
          {
            "text" : "Mike",
            "_index" : "users",
            "_type" : "user",
            "_id" : "Mike",
            "_score" : 1.0,
            "_source" : {
              "name_suggest" : {
                "input" : "Mike"
              }
            }
          }
        ]
      }
    ]
  }
}

I don't know why I'm receiving the "elasticsearch cluster is down!" error in my production environment when using elasticsearch.js.

I can't get data using elasticsearch.js since it's not connected to the internet.

Can anyone tell me what is the likely cause for this error?

tet
  • 1,287
  • 1
  • 17
  • 36
  • That could be several things. Check if your production server has 9200 port open, also check CORS, your site must be enable. – Hosar Mar 03 '17 at 06:49
  • Thank you for your reply. I have port 9200 open and `http.cors.enabled : true` `http.cors.allow-origin: /https?:\/\/localhost(:[0-9]+)?/` for CORS. I also tried `http.cors.allow-headers` and other settings, but it doesn't work. – tet Mar 03 '17 at 06:56

0 Answers0