# Append on update

**URL:** <https://discuss.elastic.co/t/append-on-update/116142>\
**Category:** Elasticsearch\
**Created:** [January 18, 2018, 11:41pm UTC](https://discuss.elastic.co/t/append-on-update/116142 "2018-01-18T23:41:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ranieri\_Mazili\_de\_Ol](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ranieri_mazili_de_ol/32/15815_2.png) [@Ranieri\_Mazili\_de\_Ol](https://discuss.elastic.co/u/Ranieri_Mazili_de_Ol)\
**Post date:** [January 18, 2018, 11:41pm UTC](https://discuss.elastic.co/t/append-on-update/116142/1 "2018-01-18T23:41:44Z")

</div>

Hello,

I have the following document that's created as a new document.  
[http://localhost:9200/ibmbpm/doc/task2?pretty](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](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

---

<div class="post-metadata">

**Author:** ![Ranieri\_Mazili\_de\_Ol](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ranieri_mazili_de_ol/32/15815_2.png) [@Ranieri\_Mazili\_de\_Ol](https://discuss.elastic.co/u/Ranieri_Mazili_de_Ol)\
**Post date:** [January 19, 2018, 12:00am UTC](https://discuss.elastic.co/t/append-on-update/116142/2 "2018-01-19T00:00:51Z")

</div>

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"  
> }  
> }  
> }  
> }

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 16, 2018, 12:00am UTC](https://discuss.elastic.co/t/append-on-update/116142/3 "2018-02-16T00:00:57Z")

</div>

Closed on February 16, 2018, 12:00am UTC

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