# Iam trying to add a new element(object) to an array

**URL:** https://discuss.elastic.co/t/iam-trying-to-add-a-new-element-object-to-an-array/134170
**Category:** Elasticsearch
**Created:** [June 1, 2018, 8:32am UTC](https://discuss.elastic.co/t/iam-trying-to-add-a-new-element-object-to-an-array/134170 "2018-06-01T08:32:11Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![pidugusundeep](https://avatars.discourse-cdn.com/v4/letter/p/ee7513/32.png) [@pidugusundeep](https://discuss.elastic.co/u/pidugusundeep)
#### Post date: [June 1, 2018, 8:32am UTC](https://discuss.elastic.co/t/iam-trying-to-add-a-new-element-object-to-an-array/134170/1 "2018-06-01T08:32:12Z")

</div>

[https://pastebin.com/1jnSVVJ7](https://pastebin.com/1jnSVVJ7)

this has the code which iam referring to and the method starting from LINE\_23 is always adding a null to the array list how do i fix this ?

---

<div class="post-metadata">

### Author: ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)
#### Post date: [June 8, 2018, 3:13pm UTC](https://discuss.elastic.co/t/iam-trying-to-add-a-new-element-object-to-an-array/134170/2 "2018-06-08T15:13:39Z")

</div>

Try this:

```auto
POST testing/doc/1/_update
{
  "_id": "1",
  "script": {
    "lang": "painless",
    "source": "ctx._source.speech_number.add(params.speech_number)",
    "params": {
      "speech_number": {"jack":"jac11k"}
    }
  }
}

```

---

<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, 2018, 3:13pm UTC](https://discuss.elastic.co/t/iam-trying-to-add-a-new-element-object-to-an-array/134170/3 "2018-07-06T15:13:46Z")

</div>

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