Elasticsearch脚本:更新数组值
这是我的文件
{ "name": "andrew",
"b": [{"x":"c1", "y": 0}, {"x":"c2", "y": 0}]
}
我想在数组字段“ b”中找到元素并更新整个对象。我尝试了此脚本,但它没有更新。有任何想法吗?
{ "script": "for (item in ctx._source.b) { if (item['x'] == x_id) { item = newobj; } };",
"params": {
"x_id": "c1",
"newobj" : {"x":"c1", "y": 4222}
},
"lang":"groovy"
}
回答:
使用此代替:
{ "script": "for (int i=0;i<ctx._source.b.size();i++) { item=ctx._source.b[i]; if (item['x'] == x_id) { ctx._source.b[i] = newobj} };",
"params": {
"x_id": "c1",
"newobj": {
"x": "c1",
"y": 4222
}
},
"lang": "groovy"
}
以上是 Elasticsearch脚本:更新数组值 的全部内容, 来源链接: utcz.com/qa/433569.html