操作别名的两个方法:_alias:单个操作_aliases:多个操作,原子性的操作
创建别名curl -XPUT 'localhost:9200/dm_v1/_alias/dm'curl -XPOST 'http://localhost:9200/_aliases' -d '{ "actions" : [ { "add" : { "index" : "dm_v1", "alias" : "dm_alias" } } ]}'
删除别名curl -XPOST 'http://localhost:9200/_aliases' -d '{ "actions" : [ { "remove" : { "index" : "dm_v1", "alias" : "dm_alias" } } ]}'curl -XDELETE 'localhost:9200/dm_v1/_alias/dm_alias'
删除别名的同时添加别名到新的索引,该操作时原子性的,不用担心存在别名没有指向任何索引的瞬间Renaming an alias is a simple remove then add operation within the same API. This operation is atomic, no need to worry about a short period of time where the alias does not point to an index:curl -XPOST 'http://localhost:9200/_aliases' -d '{ "actions" : [ { "remove" : { "index" : "dm_v1", "alias" : "dm" } }, { "add" : { "index" : "dm_v2", "alias" : "dm" } } ]}'
查询别名通过别名查询所指向的索引:curl -XGET 'localhost:9200/_alias/dm'curl -XGET 'localhost:9200/_alias/dm*'查询指向该索引下的所有别名:curl -XGET 'localhost:9200/dm_v2/_alias/*'
也可以通过head检测别名是否存在curl -XHEAD -i 'localhost:9200/_alias/dm'curl -XHEAD -i 'localhost:9200/_alias/dm*'curl -XHEAD -i 'localhost:9200/dm_v2/_alias/*'
别名应该算是搞定啦,后面就是数据的迁移啦。前面有一篇用hadoop操作ES的可以参考。使用scan scroll来批量读取,bulk API批量索引数据应该是一种高效的方法。后续可以再写一个详细的实现啦。That's all!