{
"script": {
"source": "ctx._source['servantOa']='chushihua'"
},
"query": {
"match_all": {}
}
}
嵌套结构的数据修改,
只能是单条数据
http://localhost:9488/baochuan/book/701316/_update
{
"script": {
"source": "for (item in ctx._source.level) { if (item['twoLevelId'] == params.twoLevelId) { item['twoLevelIdName'] = params.twoLevelIdName}}",
"lang": "painless",
"params": {
"twoLevelId": 7,
"twoLevelIdName": "军事后勤数据库"
}
}
}
多条更新,经典操作
http://localhost:9488/baochuan/book/_update_by_query
{
"script": {
"source": "for(e in ctx._source.level){if (e.twoLevelId== 7) {e.twoLevelIdName = '军事后勤数据库'}}",
"lang": "painless"
},
"query": {
"bool": {
"must": [
{
"nested": {
"path": "level",
"query": {
"match": {
"level.twoLevelId": 7
}
}
}
}
]
}
}
}
循环,== 和 = 等于赋值,“” 不行 ‘’