Insert Object Data using Update

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 POST

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

I got this error:

image

Any Idea how to do it ?

Thank You

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

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"
  }

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

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

Thanks a lot

Best Regards,

Adityo Setyonugroho

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