# Updating nested field with update\_by\_query API

**URL:** <https://discuss.elastic.co/t/updating-nested-field-with-update-by-query-api/53910>\
**Category:** Elasticsearch\
**Created:** [June 24, 2016, 4:22pm UTC](https://discuss.elastic.co/t/updating-nested-field-with-update-by-query-api/53910 "2016-06-24T16:22:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![diegos](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@diegos](https://discuss.elastic.co/u/diegos)\
**Post date:** [June 24, 2016, 4:22pm UTC](https://discuss.elastic.co/t/updating-nested-field-with-update-by-query-api/53910/1 "2016-06-24T16:22:56Z")

</div>

Hello, I'm trying to update a nested field of my document through the update\_by\_query API, but I"m getting a casting error: [class\_cast\_exception] java.lang.String cannot be cast to java.util.Map

This is the body of my request;

```
{  
    "query":{  
        "term":{  
            "acl_policy.group_id":"11550"
        }
    },
    "script":"ctx._source.acl_policy = newAclPolicy",
    "params":{  
        "newAclPolicy":{  
            "group_id":"11550",
            "canned_group":"company",
            "name_normalized":"",
            "members":[  
                {  
                    "user_id":"0",
                    "company_id":"4390",
                    "membership":"allow"
                }
            ]
        }
    }
}

```

Is there any fix for this?

---

<div class="post-metadata">

**Author:** ![Artistan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/artistan/32/12160_2.png) [@Artistan](https://discuss.elastic.co/u/Artistan)\
**Post date:** [September 26, 2016, 7:00pm UTC](https://discuss.elastic.co/t/updating-nested-field-with-update-by-query-api/53910/2 "2016-09-26T19:00:57Z")

</div>

I just had this SAME issue exactly.  
I was looking at the documentation for the wrong version and there is a slight syntax difference. Looks like you need to wrap the script and specify inline for the version if yours is similar version as mine.

```
curl -XPOST 'localhost:9200/scraped_links/_update_by_query' -d '{
	"script": {
		"inline":"ctx._source.scraped_data = 0"
	},
	"query": {
		"term": {
			"scraped_data": 1
		}
	}
}'
```

---

<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 5, 2017, 10:17pm UTC](https://discuss.elastic.co/t/updating-nested-field-with-update-by-query-api/53910/3 "2017-07-05T22:17:13Z")

</div>


