# Update nested object in ElasticSearch

**URL:** https://discuss.elastic.co/t/update-nested-object-in-elasticsearch/200751
**Category:** Logstash
**Created:** [September 23, 2019, 8:23pm UTC](https://discuss.elastic.co/t/update-nested-object-in-elasticsearch/200751 "2019-09-23T20:23:59Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![MMH](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mmh/32/54449_2.png) [@MMH](https://discuss.elastic.co/u/MMH)
#### Post date: [September 23, 2019, 8:23pm UTC](https://discuss.elastic.co/t/update-nested-object-in-elasticsearch/200751/1 "2019-09-23T20:23:59Z")

</div>

In one of my pipelines I am using logstash with JSON input and output to Elasticsearch with `action => "update"`.  
One of the document fields contains nested data type. If in input JSON I receive following:

> "nested\_field":{"ident":"1","someField":"someVal"}

I should update `nested_field`, find objct with value `1` in field `ident` and for this object update field `someField` to `someVal`.  
Is such operation possible in Logstash?

---

<div class="post-metadata">

### Author: ![stefws](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stefws/32/6442_2.png) [@stefws](https://discuss.elastic.co/u/stefws)
#### Post date: [September 23, 2019, 8:55pm UTC](https://discuss.elastic.co/t/update-nested-object-in-elasticsearch/200751/2 "2019-09-23T20:55:12Z")

</div>

Yes it is...

```
filter {
   # either conditional
   if [nested_field][ident] == '1' {
      # use any filter plugin to alter [nested_field][someField]
   }

  # or use the alter plugin
  alter {
     condrewriteother => [
       "[nested_field][ident]", "1", "[nested_field][someField]", "new_value"
    ]
  }
}
```

---

<div class="post-metadata">

### Author: ![MMH](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mmh/32/54449_2.png) [@MMH](https://discuss.elastic.co/u/MMH)
#### Post date: [September 23, 2019, 8:58pm UTC](https://discuss.elastic.co/t/update-nested-object-in-elasticsearch/200751/3 "2019-09-23T20:58:51Z")

</div>

Thank you for answer, but maybe I will describe my problem more through.  
I have already in ElasticSearch document, with objects in `nested_field`. I need to update one of these objects (in ElasticSearch) using Logstash, but not to change other objects in `nested_field`.

---

<div class="post-metadata">

### Author: ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)
#### Post date: [September 23, 2019, 9:15pm UTC](https://discuss.elastic.co/t/update-nested-object-in-elasticsearch/200751/4 "2019-09-23T21:15:09Z")

</div>

I think you are looking for the [update\_by\_query](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html) API in elasticsearch. You can do that using a POST from an http filter, similar to the delete field script in the other thread.

---

<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: [October 21, 2019, 9:15pm UTC](https://discuss.elastic.co/t/update-nested-object-in-elasticsearch/200751/5 "2019-10-21T21:15:10Z")

</div>

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