Ranieri Mazili
Ranieri Mazili

Reputation: 833

Partial update overwriting whole structure

I'm indexing a new document with the following content

{
    "lastUpdate" : "20180114144020452",
    "name" : "My Process",
    "startDate" : "20180114162356585",
    "endData" : "",
    "tasks" : [
        {
            "1" : {
                "lastUpdate" : "20180114144020452",
                "taskId" : "123",
                "subject" : "Terceira Atividade",
                "status" : "Active",
                "type" : "userTask",
                "assign" : [
                    {
                        "date" : "20180114144020452",
                        "type" : "role",
                        "name" : "Time 3",
                        "id" : "Team3_345"
                    }
                ],
                "receivedDate" : "",
                "readDate" : "",
                "finishDate" : ""
            }
        }
    ]
}

And then I'm trying to change task.1.status value with the following update content

{
    "doc" : {
        "tasks" : [
            {
                "1" : {
                    "status" : "Closed"
                }
            }
        ]
    }
}

But it's overwriting the whole task.1 structure, deleting other values and letting only status value to closed instead of keep other values and change only status value.

How can I solve this? Thanks

Upvotes: 0

Views: 31

Answers (1)

Val
Val

Reputation: 217504

You need to do it via a scripted partial updated like this

POST updates/update/1/_update
{
  "script": {
    "source": "ctx._source.tasks[0].1.status = 'Closed'"
  }
}

Upvotes: 2

Related Questions