Elasticsearch alias 使用

索引别名

一个索引可以接受多个别名,而一个别名也可以映射到多个索引,当指定别名时,别名将自动扩展到添加的索引。别名也可以关联到 filter,然后自动应用到检索,和 routing value。别名不能与索引同名。

添加别名,移除别名示例:

POST /_aliases
{
    "actions" : [
        { "add" : { "index" : "test1", "alias" : "alias1" } },
        { "remove" : { "index" : "test1", "alias" : "alias2" } }
    ]
}

在同一个 API 接口中可以先移除然后添加操作。该操作是原子操作,无需担心别名不指向任何一个索引的短暂瞬间:

POST /_aliases
{
    "actions" : [
        { "remove" : { "index" : "test1", "alias" : "alias1" } },
        { "add" : { "index" : "test2", "alias" : "alias1" } }
    ]
}
过滤器别名

创建过滤器别名,必须要有相应的字段映射。过滤器可以使用 Query DSL 定义,该别名可以用来检索,计数,删除等操作。

PUT /test1
{
  "mappings": {
    "_doc": {
      "properties": {
        "user" : {
          "type": "keyword"
        }
      }
    }
  }
}
Routing

可以将路由值与别名相关联。此功能可以与过滤器别名一起使用,以避免不必要的分片操作。

POST /_aliases
{
    "actions" : [
        {
            "add" : {
                 "index" : "test",
                 "alias" : "alias1",
                 "routing" : "1"
            }
        }
    ]
}
创建索引的时候指定
curl -X PUT "localhost:9200/logs_20162801" -H 'Content-Type: application/json' -d'
{
    "mappings" : {
        "_doc" : {
            "properties" : {
                "year" : {"type" : "integer"}
            }
        }
    },
    "aliases" : {
        "current_day" : {},
        "2016" : {
            "filter" : {
                "term" : {"year" : 2016 }
            }
        }
    }
}
'
参考
  1. 使用:https://www.elastic.co/guide/en/elasticsearch/reference/6.4/indices-aliases.html
  2. cat aliases:https://www.elastic.co/guide/en/elasticsearch/reference/6.4/cat-alias.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值