Updating nested field with update_by_query API

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?

1 Like

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
		}
	}
}'
2 Likes