# Updating nested fields with updateAPI

**URL:** <https://discuss.elastic.co/t/updating-nested-fields-with-updateapi/91948>\
**Category:** Elasticsearch\
**Created:** [July 5, 2017, 3:32pm UTC](https://discuss.elastic.co/t/updating-nested-fields-with-updateapi/91948 "2017-07-05T15:32:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![carolinaloureiro](https://avatars.discourse-cdn.com/v4/letter/c/a88e57/32.png) [@carolinaloureiro](https://discuss.elastic.co/u/carolinaloureiro)\
**Post date:** [July 5, 2017, 3:32pm UTC](https://discuss.elastic.co/t/updating-nested-fields-with-updateapi/91948/1 "2017-07-05T15:32:49Z")

</div>

Hi all,

I have a question regarding ES Update API.  
I have the following API update query, which works for this specific case:

```
POST regdocs/regdoc/_update_by_query
{
  "script": {
    "lang": "painless",
    "inline": "if (
ctx._source.nested[0].nested[0].nested[0].nested[0].nested[0].nested[0].references.level_1[0].external_ref_id == params.view.user
     ){ctx._source.nested[0].nested[0].nested[0].nested[0].nested[0].nested[0].references.level_1[0].internal_ref = \"it_works\"}",
  "params": {
       "view": {
            "user": "id_to_search_for"
       } 
    }
  }
}

```

However, I want to be able to do this search without having to specify the position of the array in which `id_to_search_for` will appear, as I don't know this. The depth is always the same, it's just the position I don't know.

How can I do something like `ctx._source.*.references.*.external_ref_id` where I dont have to specify the entry? (it could also be something along the lines of `nested[_]`)

---

<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:** [August 2, 2017, 3:33pm UTC](https://discuss.elastic.co/t/updating-nested-fields-with-updateapi/91948/2 "2017-08-02T15:33:15Z")

</div>

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