Update parent doc in scripted _update_by_query

I have a parent/child relation with join datatype. Now I want to update a parent document, based on a query which find's X children. I need to add the value of a field from each child to a field of the parent of that child.

Is it possible to access the parent in a _update_by_query statement? Or is it possible to query the parent document by ID in the script? I could not find any answer yet. Here is what I try to achieve:

POST test/_update_by_query
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "clusterId": {
              "value": "123"
            }
          }
        }
      ],
      "must_not": [
        {
          "term": {
            "joinType": {
              "value": "c"
            }
          }
        }
      ]
    }
  },
  "script": {
    "source": "if (ctx._source['parent'].queries == null){ctx._source['parent'].queries = new ArrayList()}ctx._source['parent'].queries.add(ctx._source['query'])",
    "lang": "painless"
  }
}

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