ElasticSearch | The “data” argument must be one of type string, TypedArray, or DataView

I'm learning ElasticSearch (hosted on AWS). I'm using the javascript sdk and this connectionClass.

My code:

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();

Problem: When I run the code I get the following error:

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

I cant figure out what the problem is, any help is appreciated.

Answers:

Answer

I am not sure how useful this answer will be to you 4 months later but I ran into the same problem and the solution was to set the region for the AWS sdk. There are a number of approaches to this, the one I used was pulling in the aws-sdk to my server.js file and adding AWS.config.update({ region: "us-west-2" });

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.