- 场景:
当索引发生变化的时候,比如领导要求对字段a进行分词,我们可以使用该功能,新建一个索引将数据迁移过去,删掉原索引,再根据场景新建,将数据迁移回来就🆗了。
// 1. 将数据迁移到新的索引
POST _reindex
{
"source": {
"index": "old_index"
},
"dest": {
"index": "new_index"
}
}
// 2. 删除老索引
DELETE /old_index
// 3. 新建索引并设置mapping
PUT /old_index
{
"mappings": {
"properties": {
"a":{
"type": "text",
"analyzer": "ik_smart"
},
"b":{
"type": "text",
"analyzer": "ik_max_word"
}
}
}
}
// 4. 将数据迁移回到原索引
POST _reindex
{
"source":{
"index":"new_index"
},
"dest":{
"index":"old_index"
}
}