Elasticsearch模块功能之-索引别名(Index aliases )

Elasticsearch模块功能之-索引别名(Index aliases )

 

Elasticsearch的API支持给索引起别名,有了别名之后可以像使用索引一样使用它。但不只是这些,一个别名可以映射多个索引,所以在需要经常指定多个索引查询的情况下,大可将所查询的索引起一个别名来查。别名也可以将索引查询的过滤条件包含在内,使用别名查询时可以查询索引的一个子集。

         创建一个别名

 

[html]  view plain copy
 
  1. curl -XPOST 'http://localhost:9200/_aliases'-d '  
  2. {  
  3.     "actions" : [  
  4.         { "add" : { "index" : "test1","alias" : "alias1" } }  
  5.     ]  
  6. }'  

 

上述将创建一个指向索引test1的别名alias1。

         删除别名:

 

[html]  view plain copy
 
  1. curl -XPOST 'http://localhost:9200/_aliases'-d '  
  2. {  
  3.     "actions" : [  
  4.         { "remove" : { "index" : "test1","alias" : "alias1" } }  
  5.     ]  
  6. }'  

上述将删除别名alias1.

 

         重命名别名:

[html] view plain copy
 
  1. curl -XPOST 'http://localhost:9200/_aliases' -d '  
  2. {  
  3.     "actions" : [  
  4.         { "remove" : { "index" : "test1", "alias" : "alias1" } },  
  5.         { "add" : { "index" : "test1", "alias" : "alias2" } }  
  6.     ]  
  7. }'  

 

创建映射多个索引的别名:

[html]  view plain copy
 
  1. curl -XPOST 'http://localhost:9200/_aliases'-d '  
  2. {  
  3.     "actions" : [  
  4.         { "add" : { "index" : "test1","alias" : "alias1" } },  
  5.         { "add" : { "index" : "test2","alias" : "alias1" } }  
  6.     ]  
  7. }'  

上述创建的别名alias1映射索引test1和索引test2。

 

创建索引在索引创建期间:

 

[html]  view plain copy
 
  1. curl -XPUT localhost:9200/logs_20142801 -d '{  
  2.     "aliases" : {  
  3.         "current_day" : {},  
  4.         "2014" : {  
  5.             "filter" : {  
  6.                 "term" : {"year": 2014 }  
  7.             }  
  8.         }  
  9.     }  
  10. }'  

 

 

查看索引是所有别名:

 

[html]  view plain copy
 
  1. curl -XGET 'localhost:9200/users/_alias/*<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);"> </span>  

 

查看具体别名:

 

[html]  view plain copy
 
  1. curl -XGET 'localhost:9200/_alias/2013'  

 

包含过滤条件的别名:

 

[html]  view plain copy
 
  1. curl -XPOST 'http://localhost:9200/_aliases' -d '  
  2. {  
  3.     "actions" : [  
  4.         {  
  5.             "add" : {  
  6.                  "index" : "test1",  
  7.                  "alias" : "alias2",  
  8.                  "filter" : { "term" : { "user" : "kimchy" } }  
  9.             }  
  10.         }  
  11.     ]  
  12. }'  

 

上述的别名将映射到索引test1使用过滤条件之后的结果,类似数据库的视图。

 

【参考】:http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-aliases.html#indices-aliases

 

 

from http://blog.csdn.net/changong28/article/details/38424143

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值