【问题标题】:How to connect to AWS ElasticSearch using npm elasticsearch and http-aws-es?如何使用 npm elasticsearch 和 http-aws-es 连接到 AWS ElasticSearch?
【发布时间】:2019-04-04 19:39:52
【问题描述】:

我正在使用 npm elasticsearch 包来搜索我的 AWS ES 域。当我使用 Postman 使用我的 AWS IAM 凭证发出 POST 请求时,一切似乎都运行良好。 我想在我的代码(node.js)中做同样的事情。我在这里提到了这个答案: How to make calls to elasticsearch apis through NodeJS?

代码如下:

const elasticsearch     = require('elasticsearch');
const awsHttpClient     = require('http-aws-es');
const AWS               = require('aws-sdk');

const client            = new elasticsearch.Client({ 
    host: 'my-aws-es-endpoint', 
    connectionClass: awsHttpClient,
    amazonES: {
        region: 'us-east-1',
        credentials: new AWS.Credentials('my-access-key','my-secret-key')
    }
});

但是当我运行 client.search() 时,它失败并出现错误:

Elasticsearch ERROR: 2018-10-31T15:12:22Z
  Error: Request error, retrying
  POST https://my-endpoint.us-east-1.es.amazonaws.com/my-index/student/_search => Data must be a string or a buffer

它也给了我一个警告

Elasticsearch WARNING: 2018-10-31T15:12:22Z
  Unable to revive connection: https://my-endpoint.us-east-1.es.amazonaws.com/

当我只使用 aws-sdk 时,它工作正常(可能是因为我在那里签署了请求?)

有人可以建议我在这里做错了什么吗?

【问题讨论】:

    标签: node.js amazon-web-services elasticsearch aws-sdk aws-elasticsearch


    【解决方案1】:

    我可以通过指定区域来解决这个问题。 elasticsearch 客户端存在问题,无法选择我们在其中指定的区域

    amazonES: {
            region: 'us-east-1',
            credentials: new AWS.Credentials('my-access-key','my-secret-key')
        }
    }
    

    我通过在上述代码之前使用 AWS.config.region 指定区域来解决它

    AWS.config.region = 'us-east-1';
    

    【讨论】:

      猜你喜欢
      • 2018-02-08
      • 2016-01-29
      • 2017-09-06
      • 2019-12-24
      • 2021-08-11
      • 2018-05-04
      • 2021-02-01
      • 2016-11-26
      • 2021-12-31
      相关资源
      最近更新 更多