脚本参数不支持以下类型的值:ElasticSearch v7.3 Update脚本中的START_ARRAY [英] script params doesn't support values of type: START_ARRAY in ElasticSearch v7.3 Update script

查看:445
本文介绍了脚本参数不支持以下类型的值:ElasticSearch v7.3 Update脚本中的START_ARRAY的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为索引更新文档,并通过邮递员在更新API脚本上遇到以下错误

I am trying to update the document for my index and getting the following error on update API script through Postman

{
    "error": {
        "root_cause": [
            {
                "type": "x_content_parse_exception",
                "reason": "[5:15] [script] params doesn't support values of type: START_ARRAY"
            }
        ],
        "type": "x_content_parse_exception",
        "reason": "[5:15] [UpdateRequest] failed to parse field [script]",
        "caused_by": {
            "type": "x_content_parse_exception",
            "reason": "[5:15] [script] params doesn't support values of type: START_ARRAY"
        }
    },
    "status": 400
}

由于错误明确表明我正在更新文档中包含数据数组的字段。这是一个示例

As the error is clearly stating that I am updating a field in my document which has an array of data. Here is a sample

"hasParts": [
    {
        "documentLevel": 2,
        "levelProperties": {
            //some properties
        }
    },
    {
        "documentLevel": 3,
        "levelProperties": {
            //some properties
        }
    },
    {
        "documentLevel": 3,
        "levelProperties": {
           //some properties
        }
    },
    {
        "documentLevel": 3,
        "levelProperties": {
            //some properties
        }
    }
]

我想使用一个更新API更新上述属性

I want to update the above property using Update API for one of the document.

这可能吗?如果有可能,那我在做什么错?
预先感谢您的帮助。

Can this be possible? If it is possible then what am I doing wrong? Thanks in Advance for the help.

编辑:
这是脚本

Here is the script

{
  "script": {
    "source": "ctx._source.hasParts.add(params.haspart)",
    "lang": "painless",
    "params": [
      {
        "haspart": [
          {
            "documentLevel": 3,
            "levelProperties": {
              //some properties
            }
          },
          {
            "documentLevel": 3,
            "levelProperties": {
              //some properties
            }
          },
          {
            "documentLevel": 3,
            "levelProperties": {
              //some properties
            }
          },
          {
            "documentLevel": 3,
            "levelProperties": {
              //some properties
            }
          },
          {
            "documentLevel": 3,
            "levelProperties": {
              //some properties
            }
          }
        ]
      }
    ]
  }
}


推荐答案

您的 params 部分不能是数组,而是对象,请改用以下脚本:

Your params section must not be an array, but an object, use this script instead:

{
  "script": {
    "source": "ctx._source.hasParts.add(params.haspart)",
    "lang": "painless",
    "params": {
        "haspart": [
          {
            "documentLevel": 3,
            "levelProperties": {
              //some properties
            }
          },
          {
            "documentLevel": 3,
            "levelProperties": {
              //some properties
            }
          },
          {
            "documentLevel": 3,
            "levelProperties": {
              //some properties
            }
          },
          {
            "documentLevel": 3,
            "levelProperties": {
              //some properties
            }
          },
          {
            "documentLevel": 3,
            "levelProperties": {
              //some properties
            }
          }
        ]
    }
  }
}

这篇关于脚本参数不支持以下类型的值:ElasticSearch v7.3 Update脚本中的START_ARRAY的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆