So, I've successfully created a field and added a value for it in existing documents using the put mapping and update by query APIs with the following
NEW_FIELD = {
'properties': {
'deleted': {
'type': 'boolean'
}
}
}
UPDATE_QUERY = {
'script': {
'source': 'ctx._source.deleted = false',
'lang': 'painless'
},
'query': {
'match_all': {}
}
}
Now, the same won't work for a field that is inside an existing array, I was able to create the field but the update query doesn’t seem to be correct:
NEW_FIELD = {
'properties': {
'customer': {
'properties': {
'sensitive': {
'type': 'boolean'
}
}
}
}
}
UPDATE_QUERY = {
'script': {
'source': 'ctx._source.customer.sensitive = false',
'lang': 'painless'
},
'query': {
'match_all': {}
}
}