我正在使用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时,它可以正常工作(可能是因为我在那儿签署了请求?)
有人可以建议我在这里做错了吗?
答案 0 :(得分:2)
我能够通过指定区域来解决此问题。 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';