`

elasticsearch的索引如何才能做到平滑切换

阅读更多

        需求:

        我有一个shoptopic_20150916的index,我需要把shoptopic_20150916的数据索引到shoptopic_20150917上,但shoptopic_20150916索引的数据还在不断增加,用户还在写入数据,我怎么把shoptopic_20150917替换shoptopic_20150916,而且在不重启集群的情况下?

 

 

   这个你可以使用别名的方法来实现索引的零宕机时间切换。

具体实现方法如下:
 
1.为老索引建立别名 

# curl -XPUT http://ESnode:9200/shoptopic_20150916/_alias/shoptopic_20150916as

2.建立新索引shoptopic_20150917

# curl -XPOST "http://ESnode:9200/shoptopic_20150917"

3.重导入shoptopic_20150916的数据到shoptopic_20150917
4.数据重跑完成后,切换索引

# curl -XPOST http://ESnode:9200/_aliases
{
"actions": [
{ "remove": { "index": "old_index", "alias": "my_index" }},
{ "add": { "index": "new_index", "alias": "my_index" }}
]
}

可以去了解es的别名做操作,参考链接:http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics