首页 > IT基础架构 > > Elasticsearch给全部文档添加新的字段
script.engine.groovy.inline.aggs: on
script.engine.groovy.inline.search: on
script.engine.groovy.inline.update: on或者
script.inline: true
scan anc scroll all documents
use /_search?scroll to fetch the docs
perform your operation
send /_bulk update requestsPOST bt/bt/_update
{
"script" : "ctx._source.new_field = \"value_of_new_field\""
}
POST bt/bt/_update_by_query
{
"script": {
"inline": "if (ctx._source.bt0 == null || ctx._source.bt1==null) { ctx._source.btNew1=null } else { ctx._source.btNew1 = ctx._source.bt0 + ctx._source.bt1 }"
}
}
{
"source": {
"index": "bt",
"type": "bt"
},
"dest": {
"index": "new_bt1"
},
"script": {
"inline": "if (ctx._source.bt0 == null || ctx._source.bt1==null) { ctx._source.btPlus=null } else { ctx._source.btPlus = ctx._source.bt0 + ctx._source.bt1 }"
}
}
其实_update_and_query和_reindex的实现差不多,性能没有测过,不过应该差不多。所以elasticsearch还有task api可以用来检测这两个任务运行情况。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69946831/viewspace-3125102/ ,如需转载,请注明出处,否则将追究法律责任。