node.js - 端口 9200 拒绝连接?

标签 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)

.

我的 Elasticsearch 客户端代码非常简单

    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,我没有收到拒绝错误,但弹性集群仍然关闭?任何建议都会有所帮助,谢谢:)

最佳答案

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

关于node.js - 端口 9200 拒绝连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31065018/

相关文章:

java - Elasticsearch 中的 JSON 格式化

node.js - 用于应用程序身份验证的 OpenLDAP 本地配置

node.js - 在 Angular 2 typescript 中包含 lib 时找不到模块 "shelljs"

elasticsearch - 对子文档字段值的Elasticsearch聚合

elasticsearch - Elasticsearch 与Lucene

elasticsearch - 动态更新ES 2.4.1中的慢速日志?

node.js - 使用 Jenkins 运行 Grunt.js

node.js - 找不到模块 : Error: Can't resolve 'fs' with webpack

javascript - 如何在nodejs中维护事件循环的持久数据?

.net - ElasticSearch Nest - 仅使用索引名进行查询