加 “conflicts”: “proceed” ,错了多执行几次,最后会全部成功
POST /your_index/_update_by_query
{
"script": {
"source": """
if (!ctx._source.containsKey('a') || ctx._source.a == '') {
ctx._source.a = 'v1';
}
ctx._source.b = 'v2';
"""
},
"query": {
"bool": {
"should": [
{"bool": {"must_not": {"exists": {"field": "a"}}}},
{"match": {"a": ""}}
]
}
},
"conflicts": "proceed"
}