# Updating elastic search document by id is not working

**URL:** <https://discuss.elastic.co/t/updating-elastic-search-document-by-id-is-not-working/316240>\
**Category:** Elasticsearch\
**Created:** [October 10, 2022, 3:15pm UTC](https://discuss.elastic.co/t/updating-elastic-search-document-by-id-is-not-working/316240 "2022-10-10T15:15:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Atul\_Joshi1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/atul_joshi1/32/98606_2.png) [@Atul\_Joshi1](https://discuss.elastic.co/u/Atul_Joshi1)\
**Post date:** [October 10, 2022, 3:15pm UTC](https://discuss.elastic.co/t/updating-elastic-search-document-by-id-is-not-working/316240/1 "2022-10-10T15:15:28Z")

</div>

I have document structure as below stored in Elasticsearch -

```auto
      {
        "_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 -

```auto
      {
        "_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 ?

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [October 10, 2022, 3:26pm UTC](https://discuss.elastic.co/t/updating-elastic-search-document-by-id-is-not-working/316240/2 "2022-10-10T15:26:05Z")

</div>

Hi @Atul_Joshi1

Try update like this:

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

```

---

<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:** [November 7, 2022, 3:26pm UTC](https://discuss.elastic.co/t/updating-elastic-search-document-by-id-is-not-working/316240/3 "2022-11-07T15:26:51Z")

</div>

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