一、背景
1.es 规定文档 mapping一旦建完过后就无法改动,所以当索引的 mapping 有变动时需要重建索引
2.es 规定分片一旦指定后就无法修改,所以当索引数据量随时间变大需要设置更多分片的时候需要重建索引
以上情况可以选择 reindex 命令重建索引,速度比用 bulk快 5 到 10 倍
二、使用步骤
1.新建索引
注意:在创建索引的时候要把表结构也要创建好(也就是mapping).
2.复制数据
使用restful 接口
POST _reindex
{
"source":{"index":"oldIndex"},
"dest":{"index":"newIndex"}
}
使用 curl
$ curl -X POST ‘xx.xx.xx.xx:9200/_reindex’ -d {“source”:{“index”:“old_index”},“dest”:{“index”:“new_index”}}
当新的索引里有数据时要设置"version_type": “internal” ,