# Adding a new nested object to an existing overall object

**URL:** <https://discuss.elastic.co/t/adding-a-new-nested-object-to-an-existing-overall-object/23761>\
**Category:** Elasticsearch\
**Created:** [June 16, 2015, 4:32pm UTC](https://discuss.elastic.co/t/adding-a-new-nested-object-to-an-existing-overall-object/23761 "2015-06-16T16:32:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mosiddi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mosiddi/32/577_2.png) [@mosiddi](https://discuss.elastic.co/u/mosiddi)\
**Post date:** [June 16, 2015, 4:32pm UTC](https://discuss.elastic.co/t/adding-a-new-nested-object-to-an-existing-overall-object/23761/1 "2015-06-16T16:32:36Z")

</div>

Hi guys,  
I've a scenario where I'm storing file contents and path in ES. The file mapping is simple -  
File Details = \>  
Contents  
Content hash (this is also an id of the document)  
File paths  
File path =\>  
Folder Path  
File name  
File extension  
I add the document first time if the same doesn't exists and update the File paths next time I come across a file with same content.

> [Update API | Elasticsearch Guide [8.11] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html)

I'm using script ctx.\_source.paths += path where I'm passing path as a param. The insert is working fine as part of upsert and from # of deleted document I can see update is also happening. The only problem I've is I see only the last path seen for the file. Previous is getting replaced instead of a new entry getting added to the list.

Any pointers?  
Thanks

---

<div class="post-metadata">

**Author:** ![mosiddi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mosiddi/32/577_2.png) [@mosiddi](https://discuss.elastic.co/u/mosiddi)\
**Post date:** [June 17, 2015, 3:50am UTC](https://discuss.elastic.co/t/adding-a-new-nested-object-to-an-existing-overall-object/23761/2 "2015-06-17T03:50:34Z")

</div>

Some more data. This is how the mapping looks like -

```
     "FileContract": {
        "_id": {
           "path": "documentId"
        },
        "properties": {
            "content": {
              "type": "string",
              "include_in_all": false
           },
           "contentId": {
              "type": "string",
              "index": "no",
              "store": true,
              "include_in_all": false
           },
           "documentId": {
              "type": "string",
              "index": "no",
              "include_in_all": false
           },
           "paths": {
              "type": "nested",
              "properties": {
                 "fileExtension": {
                    "type": "string",
                    "index": "not_analyzed",
                    "store": true,
                    "include_in_all": false
                 },
                 "fileExtensionId": {
                    "type": "double",
                    "store": true,
                    "include_in_all": false
                 },
                 "fileName": {
                    "type": "string",
                    "index": "not_analyzed",
                    "include_in_all": false
                 },
                 "filePath": {
                    "type": "string",
                    "index": "not_analyzed",
                    "include_in_all": false
                 },
                 "filePathOriginal": {
                    "type": "string",
                    "index": "not_analyzed",
                    "store": true,
                    "include_in_all": false
                 }
              }
           }
         }

```

This is how I'm constructing the descriptor -

```
                descriptor = descriptor.Update<T, T>(doc => doc
                    .IdFrom(item)
                    .Script("ctx._source.paths = ctx._source.paths + path")
                    .Params(p => p.Add("path", (item as FileContract).Paths[0])) // This is for testing purpose only. not a production code so using string literals and directly referring first element of array
                    .Upsert(item));
```

---

<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, 12:07am UTC](https://discuss.elastic.co/t/adding-a-new-nested-object-to-an-existing-overall-object/23761/3 "2017-07-06T00:07:09Z")

</div>


