我正在学习ElasticSearch(托管在AWS上)。 我正在使用the javascript sdk和this connectionClass。
我的代码:
let es = require('elasticsearch');
let client = new es.Client({
hosts: ['https://search-nboardelastic-xxyy.foo.es.amazonaws.com'],
connectionClass: require('http-aws-es')
});
function handler() {
let params = {
index: 'product',
q: 'bar'
};
client.search(params, (err, data) => {
if (err) {
console.log('Error ', err);
} else {
console.log('Data ', data);
}
})
}
handler();
问题: 运行代码时,出现以下错误:
Error: Request error, retrying
POST https://https://search-nboardelasticxxyy.foo.es.amazonaws.com/product/_search => The "data" argument must be one of type string, TypedArray, or DataView
at checkRespForFailure (/Users/oscarandersen/WebstormProjects/peego/lambda/indexElasticSearch/node_modules/elasticsearch/src/lib/transport.js:266:18)
at done (/Users/oscarandersen/WebstormProjects/peego/lambda/indexElasticSearch/node_modules/http-aws-es/connector.js:48:7)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:160:7)
at Function.Module.runMain (module.js:703:11)
at startup (bootstrap_node.js:193:16)
at bootstrap_node.js:617:3
我不知道问题出在什么地方,我们将不胜感激。
答案 0 :(得分:4)
我不确定四个月后此答案对您有多大帮助,但是我遇到了同样的问题,解决方案是为AWS sdk设置区域。有很多方法,我使用的方法是将aws-sdk拉入我的server.js文件并添加AWS.config.update({ region: "us-west-2" });