【问题标题】:Port 9200 Refused Connection?端口 9200 拒绝连接?
【发布时间】:2015-06-26 04:36:41
【问题描述】:

我正在尝试在 Cloud9 工作区上的 NodeJS 中实现弹性搜索客户端,我只是想让它运行。我的应用程序在端口 5678 上运行,我的 MongoDB 在 27017 上运行。我尝试搜索其他答案,但我并没有真正找到任何特别有用的东西。这是我在尝试连接到 localhost:9200 时收到的错误消息。

    Elasticsearch ERROR: 2015-06-26T04:24:19Z
  Error: Request error, retrying -- connect ECONNREFUSED
      at Log.error (/home/ubuntu/workspace/node_modules/elasticsearch/src/lib/log.js:213:60)
      at checkRespForFailure (/home/ubuntu/workspace/node_modules/elasticsearch/src/lib/transport.js:192:18)
      at HttpConnector.<anonymous> (/home/ubuntu/workspace/node_modules/elasticsearch/src/lib/connectors/http.js:153:7)
      at ClientRequest.wrapper (/home/ubuntu/workspace/node_modules/elasticsearch/node_modules/lodash/index.js:3128:19)
      at ClientRequest.emit (events.js:95:17)
      at Socket.socketErrorListener (http.js:1552:9)
      at Socket.emit (events.js:95:17)
      at net.js:441:14
      at process._tickCallback (node.js:442:13)

Elasticsearch TRACE: 2015-06-26T04:24:19Z
  -> HEAD http://localhost:9200/

  <- 0


Elasticsearch WARNING: 2015-06-26T04:24:19Z
  Unable to revive connection: http://localhost:9200/

Elasticsearch WARNING: 2015-06-26T04:24:19Z
  No living connections

Trace: elasticsearch cluster is down!
    at Server (/home/ubuntu/workspace/app.js:32:13)
    at respond (/home/ubuntu/workspace/node_modules/elasticsearch/src/lib/transport.js:251:9)
    at sendReqWithConnection (/home/ubuntu/workspace/node_modules/elasticsearch/src/lib/transport.js:171:7)
    at next (/home/ubuntu/workspace/node_modules/elasticsearch/src/lib/connection_pool.js:213:7)
    at process._tickCallback (node.js:442:13)

我的弹性搜索客户端代码很简单

    var client = new elasticsearch.Client({
  hosts: 'localhost:9200',
  log: 'trace'
});

client.ping({
  // ping usually has a 3000ms timeout
  requestTimeout: 30000,

  // 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');
  }
});

如果我尝试连接到 localhost:5678,我没有收到错误拒绝,但弹性集群仍然关闭?任何建议都会有所帮助,谢谢:)

【问题讨论】:

  • 你的 elasticsearch 正在运行吗?如果 ES 未运行或未在端口 9200 上运行,则会弹出此错误
  • 您好,非常感谢您的回复!它似乎正在运行,但它无法建立正确的连接或其他我不知道的错误。这是我定期收到的,这是我假设的 ping 请求。 Elasticsearch 跟踪:2015-06-26T19:57:21Z -> HEAD localhost:9200
  • 当我运行 npm start 添加连接到localhost:9200 Elasticsearch DEBUG: 2015-06-26T20:10:23Z 开始请求{方法:'HEAD',requestTimeout: 30000,castExists:true,路径:'/',查询:{ keepAlive:false,你好:'elasticsearch!' } }

标签: node.js elasticsearch


【解决方案1】:
//Client.js
    const es = require('elasticsearch');
    const esClient = new es.Client({
        host: {
            protocol: 'http',
            host: 'localhost',
            port: 9200

        },
        log: 'trace'
    });

    module.exports = esClient;

//ping.js
const esClient = require('./client');

esClient.ping({
// ping usually has a 3000ms timeout
    requestTimeout: 3000
}, function (error) {
    if (error) {
        console.trace('elasticsearch cluster is down!');
    } else {
        console.log('All is well');
    }
});

【讨论】:

    【解决方案2】:

    嘿,任何想知道我做了什么的人。我基本上只是将elasticsearch下载到cloud9并运行它。然后我相应地 ping 了端口并且它工作了。对我来说看起来像是一个新手错误:P

    【讨论】:

    • 嘿伙计,假设我在 ElasticSearch 的谷歌云上上传了一个实例,并且我正在使用相同的代码。它给出了错误。错误:请求错误,正在重试——getaddrinfo ENOTFOUND http
    【解决方案3】:

    在我的情况下,默认使用所有内容并使用 JS 客户端的 stock elasticsearch 会导致此错误。

    (短期)修复:http.cors.enabledhttps.cors.allow-origin 设置

    【讨论】:

      猜你喜欢
      • 2015-10-19
      • 2015-12-03
      • 2016-10-18
      • 2016-03-24
      • 1970-01-01
      • 2019-07-29
      • 1970-01-01
      • 1970-01-01
      • 2017-07-20
      相关资源
      最近更新 更多