# Adding new element to list of objects with the new name of field

**URL:** https://discuss.elastic.co/t/adding-new-element-to-list-of-objects-with-the-new-name-of-field/248275
**Category:** Elasticsearch
**Created:** [September 11, 2020, 7:10am UTC](https://discuss.elastic.co/t/adding-new-element-to-list-of-objects-with-the-new-name-of-field/248275 "2020-09-11T07:10:32Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![charvi23](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/charvi23/32/103607_2.png) [@charvi23](https://discuss.elastic.co/u/charvi23)
#### Post date: [September 11, 2020, 7:10am UTC](https://discuss.elastic.co/t/adding-new-element-to-list-of-objects-with-the-new-name-of-field/248275/1 "2020-09-11T07:10:33Z")

</div>

I am trying to add new object to list of object in an elastic search index with java HighLevelRestClient. I know I can do it with following query:

```auto
String query = "ctx._source.custom_analysis.custom_analysis_list.add(params.custom_properties)";

```

This script adds a new value to the list but does not create object in index named 'custom\_properties'

But I want the output similar to following where in a new field name (custom\_properties ) is added as well is added to the index while I add a new object to arraylist.

```auto
"custom_analysis" : {
            "custom_analysis_list" : [
              {
                "custom_properties" : {
                  "deleted" : true,
                  "name" : "Custom Analysis1",
                  "description" : "Custom analysis for yogurt ",
                  "last_modified_date" : "01-08-2020",
                  "id" : "1",
                  "creation_date" : "01-08-2020",
                  "show_on_screen" : false,
                  "type" : "yogurt_us"
                }
              },
              {
                "custom_properties" : {
                  "deleted" : false,
                  "name" : "Custom Analysis2",
                  "description" : "Custom analysis description ",
                  "last_modified_date" : "01-01-2020",
                  "id" : "2",
                  "creation_date" : "01-01-2020",
                  "show_on_screen" : false,
                  "type" : "yogurt_us"
                }
              }] 
}

```

---

<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 9, 2020, 7:10am UTC](https://discuss.elastic.co/t/adding-new-element-to-list-of-objects-with-the-new-name-of-field/248275/2 "2020-10-09T07:10:46Z")

</div>

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