Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 使用nodejs处理elasticsearch时出现连接拒绝错误_Node.js_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch - Fatal编程技术网 elasticsearch,Node.js,elasticsearch" /> elasticsearch,Node.js,elasticsearch" />

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

Node.js 使用nodejs处理elasticsearch时出现连接拒绝错误,node.js,elasticsearch,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

我正在使用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服务器后,运行节点服务器,但仍然得到这个错误(因为elasticsearch服务器在9300上运行)

由于elasticsearch的服务器在本地主机上运行良好,下面是我在终端上的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
}

一切可能吗?您确实安装并正在运行弹性搜索“服务器”,不是吗?你已经确认你可以在你的程序之外访问该服务器,不是吗?因为我在这里看不到任何能证实这两种观点的东西。因此,我们一般认为您实际上没有安装服务器,只是认为
npm安装为您做了一切。但如果您有其他证据,那么我建议您实际展示它。嘿,谢谢您的回复,服务器已经安装,并且在localhost:9200上运行良好,就像我在执行curl命令一样,没有任何问题,但是当我尝试上面的方法时,它不起作用,请帮助您展示“您的问题”是重点。这里的一个问题需要以其他人能够验证和再现的方式提出。我们不会坐在你的办公桌旁,因此需要有足够的信息才能看到实际问题。显示您有一个正在运行的服务器,并使用诸如
curl
之类的外部工具来运行它。请“不要截图”。向我们展示您是如何实际运行服务器的,并说明您的程序是试图在与服务器相同的机器上运行还是在其他地方运行。ECONNREFUSED表示您的程序没有看到服务器。再次感谢,我在问题中也编辑了此部分。您正在通过端口
9200
上的
curl
访问此部分。您的代码正在尝试使用端口
9300
。看到区别了吗<代码>头部http://localhost:9300/?hello=elasticsearch! => 分析错误
。我知道您使用
9200
显示代码,但实际情况并非如此。
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
}