我想检查elasticsearch.js是否已连接到互联网。
所以我在生产环境中运行client.ping
,如下所示。
client.ping({
requestTimeout: 30000,
}, function (error) {
if (error) {
console.error('elasticsearch cluster is down!');
} else {
console.log('All is well');
}
});
我收到一条错误日志,说“弹性搜索群集已关闭!”。
另一方面,当我在自己的机器上的开发环境中运行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.js时,我的生产环境出错。
我无法使用elasticsearch.js获取数据,因为它没有连接到互联网。
有谁能告诉我这个错误的可能原因是什么?