# Insert Object Data using Update

**URL:** https://discuss.elastic.co/t/insert-object-data-using-update/123871
**Category:** Elasticsearch
**Created:** [March 14, 2018, 9:44am UTC](https://discuss.elastic.co/t/insert-object-data-using-update/123871 "2018-03-14T09:44:38Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![adityosn](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@adityosn](https://discuss.elastic.co/u/adityosn)
#### Post date: [March 14, 2018, 9:44am UTC](https://discuss.elastic.co/t/insert-object-data-using-update/123871/1 "2018-03-14T09:44:38Z")

</div>

Hi,

I would like adding data to my new added properties. So, I have ran mapping again to update my last index mapping by adding this property:

```
"author": { 
      "properties": {
        "id": { "type": "integer" },
        "name": { 
          "properties": {
            "nicename": { "type": "text" },
            "displayname": { "type": "text" }
          }
        },
		"email": { "type": "text" }
      }

```

After I add new properties to my index, I would like to adding this part of properties data without reimport all my other properties data.

For example beside author properties I have:

1. Post ID
2. Post Content
3. Post Date

I have run UPDATE API from elastic by using this :  
[http://esURL/index/type/idcontent/\_update](http://esURL/index/type/idcontent/_update) POST

```
   {
      "script": {
        "source": "ctx._source.author.id = '10'",
        "lang": "painless"
      }
    }

```

I got this error:

![image](https://us1.discourse-cdn.com/elastic/original/3X/d/4/d453bdee306e6cc6f82508cfc052109855611704.png)

Any Idea how to do it ?

Thank You

---

<div class="post-metadata">

### Author: ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)
#### Post date: [March 14, 2018, 9:56am UTC](https://discuss.elastic.co/t/insert-object-data-using-update/123871/2 "2018-03-14T09:56:35Z")

</div>

What does your document look like before the update? Does it actually exsist? Does it have an `author` field which is an object?

---

<div class="post-metadata">

### Author: ![adityosn](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@adityosn](https://discuss.elastic.co/u/adityosn)
#### Post date: [March 14, 2018, 10:03am UTC](https://discuss.elastic.co/t/insert-object-data-using-update/123871/3 "2018-03-14T10:03:02Z")

</div>

Hi,

Thank you for your reply.

It does not exists before, I would like to update my document by just adding author without I need to add again ID, Content, and Date.

For example, I have this before mapping:

```
{
    "post_ID" : 8,
    "post_date" : 1405461244000,
    "post_content" : "CONTENT SAMPLE"
  }

```

Then, after mapping, I would like to add author data to my document, so become like this:

```
{
	"author" : {
		"email" : "user@email.com",
		"id" : 1,
		"name" : {
			"nicename" : "user",
			"displayname" : "user"
		}
	}
    "post_ID" : 8,
    "post_date" : 1405461244000,
    "post_content" : "CONTENT SAMPLE"
  }
```

---

<div class="post-metadata">

### Author: ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)
#### Post date: [March 14, 2018, 10:45am UTC](https://discuss.elastic.co/t/insert-object-data-using-update/123871/4 "2018-03-14T10:45:25Z")

</div>

Then you'll probably want to read about upserts. [https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html#upserts](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html#upserts)

---

<div class="post-metadata">

### Author: ![adityosn](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@adityosn](https://discuss.elastic.co/u/adityosn)
#### Post date: [March 14, 2018, 1:06pm UTC](https://discuss.elastic.co/t/insert-object-data-using-update/123871/5 "2018-03-14T13:06:50Z")

</div>

Thank you so much ! Yes, I can insert object type into my created document.

By using : [https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html#\_literal\_doc\_as\_upsert\_literal](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html#_literal_doc_as_upsert_literal)

Thanks a lot

Best Regards,

Adityo Setyonugroho

---

<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: [April 11, 2018, 1:07pm UTC](https://discuss.elastic.co/t/insert-object-data-using-update/123871/6 "2018-04-11T13:07:16Z")

</div>

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