elasticsearch,aws-elasticsearch,Javascript,elasticsearch,Aws Elasticsearch" /> elasticsearch,aws-elasticsearch,Javascript,elasticsearch,Aws Elasticsearch" />

Javascript ElasticSearch |和#xA0;";“数据”;参数必须是string、TypedArray或DataView类型之一

Javascript ElasticSearch |和#xA0;";“数据”;参数必须是string、TypedArray或DataView类型之一,javascript,elasticsearch,aws-elasticsearch,Javascript,elasticsearch,Aws Elasticsearch,我正在学习ElasticSearch(在AWS上托管)。 我正在使用和 我的代码: 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 p

我正在学习ElasticSearch(在AWS上托管)。 我正在使用和

我的代码:

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
错误:请求错误,正在重试
邮递https://https://search-nboardelasticxyy.foo.es.amazonaws.com/product//\u search=>data参数必须是string、TypedArray或DataView类型之一
在checkRespForFailure(/Users/oscarandersen/WebstormProjects/peego/lambda/indexElasticSearch/node_modules/elasticsearch/src/lib/transport.js:266:18)
完成时(/Users/oscarandersen/WebstormProjects/peego/lambda/indexElasticSearch/node_modules/http aws es/connector.js:48:7)
在
在进程中。_tick回调(内部/process/next_tick.js:160:7)
位于Function.Module.runMain(Module.js:703:11)
启动时(bootstrap_node.js:193:16)
在bootstrap_node.js:617:3

我想不出是什么问题,谢谢你的帮助

我不确定这个答案在4个月后对您有多有用,但我遇到了同样的问题,解决方案是为AWS sdk设置区域。有很多方法可以做到这一点,我使用的方法是将aws sdk拉入我的server.js文件并添加
aws.config.update({region:“us-west-2”})

从错误消息中,我认为您应该从hosts参数中删除
https://
。谢谢。这在糟糕的错误信息中排名很高谢谢你,本,你的回答救了我一天!