脚本参数不支持以下类型的值:ElasticSearch v7.3 Update脚本中的START_ARRAY

时间:2019-09-25 11:35:58

标签: elasticsearch postman

我正在尝试为索引更新文档,并通过邮递员在更新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
            }
          }
        ]
      }
    ]
  }
}

1 个答案:

答案 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
            }
          }
        ]
    }
  }
}