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

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

         创建一个别名

curl -XPOST 'http://localhost:9200/_aliases'-d '
{
    "actions" : [
        { "add" : { "index" : "test1","alias" : "alias1" } }
    ]
}'

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

         删除别名:

curl -XPOST 'http://localhost:9200/_aliases'-d '
{
    "actions" : [
        { "remove" : { "index" : "test1","alias" : "alias1" } }
    ]
}'

上述将删除别名alias1.


         重命名别名:

curl -XPOST 'http://localhost:9200/_aliases' -d '
{
    "actions" : [
        { "remove" : { "index" : "test1", "alias" : "alias1" } },
        { "add" : { "index" : "test1", "alias" : "alias2" } }
    ]
}'

 

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

curl -XPOST 'http://localhost:9200/_aliases'-d '
{
    "actions" : [
        { "add" : { "index" : "test1","alias" : "alias1" } },
        { "add" : { "index" : "test2","alias" : "alias1" } }
    ]
}'

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


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

curl -XPUT localhost:9200/logs_20142801 -d '{
    "aliases" : {
        "current_day" : {},
        "2014" : {
            "filter" : {
                "term" : {"year": 2014 }
            }
        }
    }
}'

查看索引是所有别名:

curl -XGET 'localhost:9200/users/_alias/*<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);"> </span>

查看具体别名:

curl -XGET 'localhost:9200/_alias/2013'


包含过滤条件的别名:

curl -XPOST 'http://localhost:9200/_aliases' -d '
{
    "actions" : [
        {
            "add" : {
                 "index" : "test1",
                 "alias" : "alias2",
                 "filter" : { "term" : { "user" : "kimchy" } }
            }
        }
    ]
}'

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


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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值