I'm trying to add a new array field into a document with painless script but failed.
Here is the document to be updated
"_source": {
"a": {}
}
I want to add a new array b under a. So I have this script
{
"script": {
"source": "ctx._source.a.b=[params.id]",
"lang": "painless",
"params": {
"id": "id001"
}
}
}
But I got below error
{
"status": 400,
"error": {
"root_cause": [
{
"reason": "object mapping for [a.b] tried to parse field [null] as object, but found a concrete value",
"type": "mapper_parsing_exception"
}
],
"type": "mapper_parsing_exception",
"reason": "object mapping for [a.b] tried to parse field [null] as object, but found a concrete value"
}
}
I tried to create an empty array by
"ctx._source.a.b=new ArrayList()"
And then append element to the array
"ctx._source.a.b.add(params.id)"
Still got the same error
Could anyone help me point out what the issue is? Many thanks.