脚本参数不支持以下类型的值:ElasticSearch v7.3 更新脚本中的 START_ARRAY [英] script params doesn't support values of type: START_ARRAY in ElasticSearch v7.3 Update script
问题描述
我正在尝试为我的索引更新文档,并在通过 Postman 更新 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.
这是脚本
{
"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 更新脚本中的 START_ARRAY的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!