Updating elastic search document by id is not working

I have document structure as below stored in Elasticsearch -

      {
        "_index" : "testIndex",
        "_type" : "_doc",
        "_id" : "6ZR6soMBLkXUqNwMnccZ",
        "_score" : 3.4454321,
        "_source" : {
          "userData" : {
            "metadata" : {
              "userId" : "testUser"
            },
            "details" : {
              "name" : "xyz",
              "address" : '123 main street',
              "rating":12
          }
        }
      }
But when I try to update its specific field by below query , it is not getting updated correctly 

  POST /testIndex/_update/6ZR6soMBLkXUqNwMnccZ
  {
    "doc" : {
	"userData.details.rating": 100
    }
  }

It gets updated wrongly as below -

      {
        "_index" : "testIndex",
        "_type" : "_doc",
        "_id" : "6ZR6soMBLkXUqNwMnccZ",
        "_score" : 3.4454321,
        "_source" : {
          "userData" : {
            "metadata" : {
              "userId" : "testUser"
            },
            "details" : {
              "name" : "xyz",
              "address" : '123 main street',
              "rating":12 // this rating field is not updated 
          }
        }
       "userData.details.rating": 100 // instead of updating the rating inside the document , it gets updated here , outside of userData  
      }

Can anybody please help here ? What is wrong here ?

Hi @Atul_Joshi1

Try update like this:

POST /testIndex/_update/6ZR6soMBLkXUqNwMnccZ
{
  "doc": {
    "userData": {
      "details": {
        "rating": 100
      }
    }
  }
}

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