# How to update nested field using query in elasticsearch 2.4?

**URL:** https://discuss.elastic.co/t/how-to-update-nested-field-using-query-in-elasticsearch-2-4/237164
**Category:** Elasticsearch
**Created:** [June 15, 2020, 3:58pm UTC](https://discuss.elastic.co/t/how-to-update-nested-field-using-query-in-elasticsearch-2-4/237164 "2020-06-15T15:58:22Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![prasad98](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/prasad98/32/64837_2.png) [@prasad98](https://discuss.elastic.co/u/prasad98)
#### Post date: [June 15, 2020, 3:58pm UTC](https://discuss.elastic.co/t/how-to-update-nested-field-using-query-in-elasticsearch-2-4/237164/1 "2020-06-15T15:58:22Z")

</div>

I have made an Elasticsearch query:

```auto
GET shop/products/_search
{
   "_source": [
      "similar_group.product_info.product_id",
      "shop_id",
      "similar_group.product_info.tags",
      "similar_group.product_info.inventory",
      "similar_group.product_info.name"
   ],
   "query": {
      "bool": {
         "must": [
            {
               "nested": {
                  "path": "similar_group.product_info",
                  "query": {
                     "bool": {
                        "must": {
                           "term": {
                              "similar_group.product_info.product_id": 82
                           }
                        }
                     }
                  }
               }
            },
            {
               "term": {
                  "shop_id": 11
               }
            }
         ]
      }
   }
}

```

Running this query, I'm getting this as a response:

```auto
{
   "took": 3,
   "timed_out": false,
   "_shards": {
      "total": 7,
      "successful": 7,
      "failed": 0
   },
   "hits": {
      "total": 1,
      "max_score": 9.741081,
      "hits": [
         {
            "_index": "shop",
            "_type": "products",
            "_id": "m11g82",
            "_score": 9.741081,
            "_source": {
               "shop_id": 11,
               "similar_group": {
                  "product_info": [
                     {
                        "product_id": 82,
                        "name": "SpiderMan Toy",
                        "tags": [],
                        "inventory": 12
                     },
                     {
                        "product_id": 44,
                        "name": "Beyblade",
                        "tags": ["mattel"],
                        "inventory": 2
                     }
                  ]
               }
            }
         }
      ]
   }
}

```

I need to update product\_id - 82 with inventory as 0 and want to add tags for it.

How should I proceed to update these two fields which I've mentioned above?

Tried to look over solution over internet, found that we can use inline-scripts. Most of the examples are in "painless" language. Elasticsearch 2.4 uses "groovy" language. It would be great if anyone can help me with this.

Thanks a lot! in advance 🙂

---

<div class="post-metadata">

### Author: ![prasad98](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/prasad98/32/64837_2.png) [@prasad98](https://discuss.elastic.co/u/prasad98)
#### Post date: [June 15, 2020, 9:54pm UTC](https://discuss.elastic.co/t/how-to-update-nested-field-using-query-in-elasticsearch-2-4/237164/2 "2020-06-15T21:54:21Z")

</div>

It would be great if anyone can help me with this issue, I'm still not able to get the desired results.

---

<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 13, 2020, 9:54pm UTC](https://discuss.elastic.co/t/how-to-update-nested-field-using-query-in-elasticsearch-2-4/237164/3 "2020-07-13T21:54:33Z")

</div>

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