javascript - Elasticsearch | "data"参数必须是字符串、TypedArray 或 DataView 类型之一

标签 javascript elasticsearch aws-elasticsearch

我正在学习 ElasticSearch(托管在 AWS 上)。 我正在使用 the javascript sdkthis 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

我无法弄清楚问题出在哪里,感谢任何帮助。

最佳答案

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

关于javascript - Elasticsearch | "data"参数必须是字符串、TypedArray 或 DataView 类型之一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56490167/

相关文章:

javascript - 如何在 localstorage 上保存数据并将该数据附加到 some body 元素

elasticsearch - 嵌套文档中文档计数的 Elasticsearch 过滤器

PHP Base64 编码 JSON 斜线问题

elasticsearch - AWS Elasticsearch 作为事件存储

elasticsearch - 安全地连接到来自Packetbeat的开放发行版Elastic

javascript - 使用下划线转换对象数组

javascript - 隐藏外部 JavaScript

elasticsearch - 更新要映射到Elasticsearch索引的数据的映射属性

elasticsearch - 与Elasticsearch中的IN运算符完全匹配

javascript - 为什么我无法在 window.location 上进行搜索?