1.简介
reindex指重建所有数据的过程,一般在mapping设置变更(字段类型和分词器字段更新)、index设置变更(分片和副本数更改等)以及数据迁移场景下使用。elasticsearch提供了两个现成的API用于完成该工作,一个是在现有索引上重建的_update_by_query,另一个是在其它索引上重建的_reindex。
POST /blog_comment_index/_update_by_query?conflicts=proceed
{
"script": {
"source": "ctx._source.likes++",
"lang": "painless"
},
"query": {
"match": {
"author": "steven"
}
}
}
- conficts:如果遇到版本冲突,覆盖并继续执行
- script:以编程语言的方式去更新文档的字段值
- query:按照条件去更新部分文档
POST /_reindex
{
"conflicts": "proceed",
"source": {
"index": "blog_comment_index",
"query": {
"match": {
"author": "steven"
}
}
},
"dest": {
"index": "blog_comment_index_new"
}
}