用reindex实现es的索引数据迁移复制
1:使用场景
1:在我们实战中可能发现我们创建的索引的mapping不满足我们的需求,但是mapping是不能更新的
2::分片数据量太大,分片数不足导致我们的数据写入以及查询都非常慢
2:操作步骤
因为reindex的API不会复制旧索引的setting以及mapping,所以我们在使用前必须为新建的索引设置自己的mapping以及setting
1:使用前提
旧索引的source参数必须为true才支持使用reindex API,否则报错indexname didn`t store _source
步骤1:新建索引
一般mapping和setting是基于原有的索引修改一些参数
PUT /my_index {
"settings": { ... any settings ... },
"mappings": {
"type_one": { ... any mappings ... },
"type_two": { ... any mappings ... },
... }
}
步骤2:复制数据
POST _reindex?slices=auto&refresh
{ “ conflicts” :“ proceded ” ,“ source” :{ “ old_index” :“ twitter” , "size": 5000},
“ dest” :{ “ new_index” :“ new_twitter” ,“ version_type” :“ external” }
}
参数详解:
conflicts: 解决版本冲突继续,不导致reindex停止:“ conflicts” :“ proceded ”
version_type:
type和id一样时旧索引覆盖新索引的数据: “ version_type” :“ internal”
type和id一样时旧索引**保留**新索引的数据: “ version_type” :“ external”
size: 每批复制数据条数设置: "size": 5000 默认1000
设置数据遍历的并行度: slices=auto&refresh auto是等于分片数,也可以设置某个值。