# Elasticsearch Output Script - Append to array

**URL:** https://discuss.elastic.co/t/elasticsearch-output-script-append-to-array/177471
**Category:** Logstash
**Created:** [April 18, 2019, 1:20pm UTC](https://discuss.elastic.co/t/elasticsearch-output-script-append-to-array/177471 "2019-04-18T13:20:57Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![AshPowell](https://avatars.discourse-cdn.com/v4/letter/a/90db22/32.png) [@AshPowell](https://discuss.elastic.co/u/AshPowell)
#### Post date: [April 18, 2019, 1:20pm UTC](https://discuss.elastic.co/t/elasticsearch-output-script-append-to-array/177471/1 "2019-04-18T13:20:57Z")

</div>

We have a JDBC input that brings in records, we would like this to do one of two things depending on certain scenarios.

If there is already an array in the master record in Elasticsearch (let's say fieldA.fieldB.fieldC.array) then append this new record to that array.  
If there is not already an array in the master record, then create the array (fieldA.fieldB.fieldC.array) and add this new record to that array, in this scenario it's possible that fieldA or fieldA.fieldB or fieldA.fieldB.fieldC might not exist at that time either.

---

<div class="post-metadata">

### Author: ![AshPowell](https://avatars.discourse-cdn.com/v4/letter/a/90db22/32.png) [@AshPowell](https://discuss.elastic.co/u/AshPowell)
#### Post date: [April 23, 2019, 1:52pm UTC](https://discuss.elastic.co/t/elasticsearch-output-script-append-to-array/177471/2 "2019-04-23T13:52:43Z")

</div>

Any help would be appreciated

---

<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: [May 21, 2019, 1:52pm UTC](https://discuss.elastic.co/t/elasticsearch-output-script-append-to-array/177471/3 "2019-05-21T13:52:48Z")

</div>

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