# Spark Elasticsearch: Append new elements to nested array of objects

**URL:** https://discuss.elastic.co/t/spark-elasticsearch-append-new-elements-to-nested-array-of-objects/284457
**Category:** Elasticsearch
**Created:** [September 17, 2021, 8:05am UTC](https://discuss.elastic.co/t/spark-elasticsearch-append-new-elements-to-nested-array-of-objects/284457 "2021-09-17T08:05:36Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Lokesh\_Loks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lokesh_loks/32/94709_2.png) [@Lokesh\_Loks](https://discuss.elastic.co/u/Lokesh_Loks)
#### Post date: [September 17, 2021, 8:05am UTC](https://discuss.elastic.co/t/spark-elasticsearch-append-new-elements-to-nested-array-of-objects/284457/1 "2021-09-17T08:05:36Z")

</div>

I have elasticsearch query to add new elements to a nested array of objects below

```auto
POST /transactions/_doc/1/_update
{
    "script": {
        "source": "ctx._source.transactions.addAll(params.transactions)",
        "params": {
            "transactions": [
                { "date": "2020-07-14T21:10:22Z", "amount": 890 },
                { "date": "2020-07-15T15:56:18Z", "amount": 54 }
            ]
        }
    }
}

```

How can I achieve this in a spark dataframe?  
spark DF:

```auto
| id| transactions|
+---+--------------------+
| 1|[[890, 2021-07-14...|
+---+--------------------+

```

```auto
 |-- id: integer (nullable = false)
 |-- transactions: array (nullable = true)
 | |-- element: struct (containsNull = true)
 | | |-- amount: long (nullable = true)
 | | |-- date: string (nullable = true)

```

---

<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: [October 15, 2021, 8:06am UTC](https://discuss.elastic.co/t/spark-elasticsearch-append-new-elements-to-nested-array-of-objects/284457/2 "2021-10-15T08:06:32Z")

</div>

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