首页 > 解决方案 > 如何让 Elasticsearch 在一个请求中接受多个 json?

问题描述

我正在使用 Elasticsearch7 并基于https://www.elastic.co/guide/en/elasticsearch/reference/current/ingest.html创建一个管道。

管道是解码base64,如下所示:

{
  "version": 1,
  "processors": [
    {
      "script": {
        "source": "ctx.decoded = ctx.data.decodeBase64();"
      }
    },
    {
      "json": {
        "field": "decoded",
        "add_to_root": true
      }
    },
    {
      "remove": {
        "field": "decoded"
      }
    }
  ]
}

将数据推送到索引时收到错误消息:

Response for request ff6dd42a-5694-4c17-b103-c37bae72af58 is not recognized as valid JSON or has unexpected fields. Raw response received: 400 {\"error\":{\"root_cause\":[{\"type\":\"script_exception\",\"reason\":\"runtime error\",\"script_stack\":[\"ctx.decoded = ctx.data.decodeBase64();\",\" ^---- HERE\"],\"script\":\"ctx.decoded = ctx.data.decodeBase64();\",\"lang\":\"painless\",\"position\":{\"offset\":22,\"start\":0,\"end\":38}}],\"type\":\"script_exception\",\"reason\":\"runtime error\",\"script_stack\":[\"ctx.decoded = ctx.data.decodeBase64();\",\" ^---- HERE\"],\"script\":\"ctx.decoded = ctx.data.decodeBase64();\",\"lang\":\"painless\",\"position\":{\"offset\":22,\"start\":0,\"end\":38},\"caused_by\":{\"type\":\"null_pointer_exception\",\"reason\":\"Cannot invoke \\\"Object.getClass()\\\" because \\\"callArgs[0]\\\" is null\"}},\"status\":400}

原因是json不是一个单一的。它是一个多 json 数据:

{
 "data": "..."
}
{
 "data": "..."
}

它们不是有效的 json 数组,所以我怎样才能让 Elasticsearch piepline 接受这种格式?

标签: elasticsearch

解决方案


推荐阅读