我正在尝试为索引更新文档,并通过邮递员在更新API脚本上遇到以下错误
{
"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
}
由于错误明确表明我正在更新文档中包含数据数组的字段。这是一个示例
"hasParts": [
{
"documentLevel": 2,
"levelProperties": {
//some properties
}
},
{
"documentLevel": 3,
"levelProperties": {
//some properties
}
},
{
"documentLevel": 3,
"levelProperties": {
//some properties
}
},
{
"documentLevel": 3,
"levelProperties": {
//some properties
}
}
]
我想使用文档之一的Update API更新上述属性。
这可能吗?如果有可能,那我在做什么错? 在此先感谢您的帮助。
编辑: 这是脚本
{
"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
}
}
]
}
]
}
}
答案 0 :(得分:2)
您的params
部分不得为数组,而应为对象,而应使用以下脚本:
{
"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
}
}
]
}
}
}