Append on update


(Ranieri Mazili De Oliveira) #1

Hello,

I have the following document that's created as a new document.
http://localhost:9200/ibmbpm/doc/task2?pretty

{
"lastUpdate" : "2018-01-14T14:40:20.452-02:00",
"tasks" : {
"1" : {
"lastUpdate" : "2018-01-14T14:40:20.452-02:00",
"taskId" : "1",
"subject" : "My first task",
"status" : "Active"
},
"2" : {
"lastUpdate" : "2018-01-14T14:50:20.452-02:00",
"taskId" : "2",
"subject" : "My second task",
"status" : "Active"
},
"3" : {
"lastUpdate" : "2018-01-14T14:55:20.452-02:00",
"taskId" : "3",
"subject" : "My third task",
"status" : "Active"
}
}
}

So I'll execute an update that add a substructure inside a specific task (in this case the first task)
http://localhost:9200/ibmbpm/doc/task2/_update?pretty

{
"doc": {
"tasks": {
"1": {
"assign" : [
{
"date" : "2018-01-14T14:40:20.452-02:00",
"type" : "user",
"name" : "t_rmazili",
"id" : "295"
}
]
}
}
}
}

Now I need to add another child inside assign structure (it's an array), but update or new document only with the structure presented on the second requisition will replace the first child, not add a new one... how can I append a new child inside assign value instead of replace it?

I really appreciate any help
Thanks


(Ranieri Mazili De Oliveira) #2

Solved with the following update.

{
"script": {
"inline": "ctx._source.tasks.1.assign.add(params.assigned)",
"params" : {
"assigned" : {
"date" : "2018-01-14T14:40:20.452-02:00",
"type" : "user",
"name" : "t_daniele",
"id" : "334"
}
}
}
}


(system) #3

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