根据条件更新某个属性信息:_index/_type/_update_by_query POST
{
"script": {
"source": "ctx._source.更新属性名称 = '新的值'",
"lang": "painless"
},
"query": {
"bool": {
"must": [
{
"match": {
"查询属性名称": "查询值"
}
}
],
"must_not": [],
"should": []
}
}
}
更新替换某个字段的某些数据:_index/_type/_update_by_query POST
例如:将moduleUrl 字段中的/dtmp/#/ 换成data-center/#/
{
"script": {
"source": "ctx._source.moduleUrl= ctx._source.moduleUrl.replace('/dtmp/#/', '/data-center/#/')"
},
"query": {
"bool": {
"must": [
{
"prefix": {
"moduleUrl.keyword": "/dtmp/#/"
}
}
]
}
}
}
同时更新多个字段用分号隔开:
{
"script": {
"source": "source": "ctx._source.更新属性名称1 = '新的值1';ctx._source.更新属性名称2 = '新的值2'"
},
"query": {
"bool": {
"must": [
{
"prefix": {
"moduleUrl.keyword": "/dtmp/#/"
}
}
]
}
}
}