使用nodejs处理elasticsearch时出现连接拒绝错误

时间:2018-05-25 05:18:31

标签: node.js elasticsearch

我正在使用nodejs进行elasticsearch,下面是我的实现

 var elasticsearch = require('elasticsearch');
var client = new elasticsearch.Client({
  host: 'localhost:9200',
  log: 'trace',
  requestTimeout: Infinity, // Tested
  keepAlive: true // Tested
});

    client.ping({
  // ping usually has a 3000ms timeout
  requestTimeout: Infinity,
  // undocumented params are appended to the query string
  hello: "elasticsearch!"
}, function (error) {
  if (error) {
    console.trace('elasticsearch cluster is down!');
  } else {
    console.log('All is well');
  }
});

当我在终端上运行时,我收到此错误

Error: Request error, retrying
  HEAD http://localhost:9200/?hello=elasticsearch! => connect ECONNREFUSED 127.0.0.1:9200
Trace: elasticsearch cluster is down!Error: No Living connections

我已尝试过各种可能的方法在互联网上解决此问题,但无法解决此问题,请帮助

我也试过这个解决方案 - >运行elasticsearch服务器后,运行节点服务器但仍然出现此错误(作为在9300上运行的elasticsearch服务器)

Error: Request error, retrying
  HEAD http://localhost:9300/?hello=elasticsearch! => Parse Error
Error: Request error, retrying
HEAD http://localhost:9300/?hello=elasticsearch! => Parse Error

由于elasticsearch的服务器在localhost上工作正常,这是我在终端上的curl命令和结果

curl -X "localhost:9200/customer/_doc?pretty"curl -X POST "localhost:9200/customer/_doc?pretty" -H 'Content-Type: application/json' -d'
> {
>   "name": "Jane Doe"
> }
> '
{
  "_index" : "customer",
  "_type" : "_doc",
  "_id" : "nywQlmMBz1ZMUBDdRy2R",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 2,
    "failed" : 0
  },
  "_seq_no" : 0,
  "_primary_term" : 1
}

0 个答案:

没有答案