端口9200拒绝连接?

时间:2015-06-26 04:36:41

标签: node.js elasticsearch

我正在尝试在Cloud9工作区上的NodeJS中实现elasticsearch客户端,而我只是想让它运行起来。我的应用程序在端口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,我没有收到错误,但弹性群集仍然关闭?任何建议都会有所帮助,谢谢:)

3 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

在我的情况下,使用默认值并使用JS客户端的一切弹性搜索会导致此错误。

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

答案 2 :(得分:0)

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