# Nested Objects Script Merge

**URL:** <https://discuss.elastic.co/t/nested-objects-script-merge/64581>\
**Category:** Logstash\
**Created:** [November 1, 2016, 3:36pm UTC](https://discuss.elastic.co/t/nested-objects-script-merge/64581 "2016-11-01T15:36:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dejwoo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dejwoo/32/25666_2.png) [@dejwoo](https://discuss.elastic.co/u/dejwoo)\
**Post date:** [November 1, 2016, 3:36pm UTC](https://discuss.elastic.co/t/nested-objects-script-merge/64581/1 "2016-11-01T15:36:28Z")

</div>

Hey all!  
Simple Question :).

I have in elastic nested field called account. Documents come from logstash which is set to doc\_as\_upsert: true,  
how to add every new account to the nested object? Using scripts?

If so, how would one do it? I have tried indexed script but I have trouble accessing logstash fields from there, original is no problem with ctx.\_source, any ideas?

Thanks

EDIT:  
I am currently trying scripts like this:  
"script": "if (! ctx.\_source.account.contains(doc['event']['account'])) { ctx.\_source.account.add(doc['event']['account'])}"  
"script": "if (! ctx.\_source.account.contains(event['account'])) { ctx.\_source.account.add(event['account'])}"  
"script": "if (! ctx.\_source.account.contains(params['account'])) { ctx.\_source.account.add(params['account'])}"

all to no avail of solving update of nested objects by adding new ones.

---

<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:** [July 6, 2017, 4:31am UTC](https://discuss.elastic.co/t/nested-objects-script-merge/64581/2 "2017-07-06T04:31:44Z")

</div>


