首页 > 解决方案 > 在添加到 ES 时 JSON 数组的 mapper_parsing_exception 错误

问题描述

我正在尝试使用以下代码将对象数组创建到 ES 中。除此参数外,其余参数均已正确插入。我认为这是因为数据类型问题

 var body = {
      "expertise": [{
          "productName": "solution architecture"
        },
        {
          "productName": "product architecture"
        }
      ]
    }

 client.index({
  index: index,
  type: type,
  body: body
}, function(error, resp, status) {
  if (error) {
    console.log(error);
    callback(error);
  }
  console.log('success');
  callback(null, event);
});

ES 支持 JSON 数组数据类型https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html那么为什么我会收到这样的错误。

我得到的错误

 "errorMessage": "[mapper_parsing_exception] failed to parse [expertise]",
  "errorType": "Error",
  "stackTrace": [
    "respond (/var/task/node_modules/elasticsearch/src/lib/transport.js:308:15)",
    "checkRespForFailure (/var/task/node_modules/elasticsearch/src/lib/transport.js:267:7)",
    "HttpConnector.<anonymous> (/var/task/node_modules/elasticsearch/src/lib/connectors/http.js:165:7)",

标签: elasticsearchaws-sdk

解决方案


这是通过更改密钥来解决的。

"expertises":  [ // instead of expertise i used expertises
        {
          "productName": "solution architecture"
        },
        {
          "productName": "product architecture"
        }
      ]

推荐阅读