0

我想检查 elasticsearch.js 是否已连接到互联网。

所以我client.ping在我的生产环境中运行如下。

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

我收到一条错误日志,上面写着“elasticsearch 集群已关闭!”。

另一方面,当我client.ping在自己的机器上的开发环境中运行时,我收到一条日志,上面写着“一切都很好”。

curl命令在生产环境中的终端上工作。

例如,以下curl命令有效。

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"
              }
            }
          }
        ]
      }
    ]
  }
}

我不知道为什么我收到“elasticsearch 集群已关闭!” 使用 elasticsearch.js 时在我的生产环境中出错。

我无法使用 elasticsearch.js 获取数据,因为它没有连接到互联网。

谁能告诉我这个错误的可能原因是什么?

4

0 回答 0