How to add an element into multi level nested Arrays in Elasticsearch

My data:

"_source": {
"owner": "102195915017611526666",
"boxes": [
{
"box_id": "999",
"items": [
    {
        "item_id": "123",
        "item_key": "x",
        "item_value": "y"
    }
]
},
{
"box_id": "888",
"items": []
}
]
}

And I want to add an item into items Array which one is in the second box ( box_id:888 ) . I know how to add item into boxes array . I have researched but found nothing. I'm new in elasticsearch. Thank you for your helps

Edit: I also tried:

"script" : {
        "inline": "for (int i = 0; i<ctx._source.boxes.length; i++ ){if(ctx._source.boxes[i].box_id == '888') ctx._source.boxes[i].add(params.newitem);}",
        "params" : {
            "newitem" : {"item_key": "x", "item_value": "y", "item_id": "342246995990409"}
    }
},
"query": {
    "match": {
        "owner": "102195915017611526666"
    }
    }
}

But I'am getting this error:

"script_stack": [
                "ctx._source.boxes[i].add(params.newitem);}",
                "                               ^---- HERE"
            ],

I have asked many people but I couldn't get any answer from anyone. Is there any elasticsearch genius? I would be very appreciate.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.