标签:search 名称 检索 last tin 命名 插入 div a*
在运行的集群中可以从一个索引切换到另一个索引
可以给多个索引进行分组
可以与路由搭配使用
准备数据阶段
PUT l1/doc/1 { "title":"我想要睡你" } PUT l2/doc/1 { "title":"你却拿我当兄弟" } PUT l3/doc/1 { "title":"不过,我不介意" }
创建别名 给l1索引创建别名a1(_aliases actions add)
POST _aliases { "actions": [ { "add": { "index": "l1", "alias": "a1" } } ] }
查看别名
GET l1/_alias
查看结果
{ "l1" : { "aliases" : { "a1" : { } } } }
删除别名(actions remove)
POST _aliases { "actions": [ { "remove": { "index": "l1", "alias": "a1" } } ] }
重命名别名(淘汰旧的索引上的别名,生成新的索引上的别名)
POST _aliases { "actions": [ { "remove": { "index": "l1", "alias": "a1" } }, { "add": { "index": "l2", "alias": "a1" } } ] }
为多个索引指向同样的别名(证实为多个索引分组)
POST _aliases { "actions": [ {"add": {"index": "l1", "alias": "a1"}}, {"add": {"index": "l2", "alias": "a1"}}, {"add": {"index": "l3", "alias": "a1"}} ] }
使用indeices数组语法在一个操作中为多个索引指向别名
多个索引指向同一别名
POST _aliases { "actions": [ {"add": {"indices": ["l1", "l2", "l3"], "alias": "a2"}} ] }
一个索引指向多个别名
POST _aliases { "actions": [ {"add": {"index": "l1", "aliases": ["a1", "a2", "a3"]}} ] }
将别名关联到拥有公共名称的索引(将索引 l1 l2 l3指向f1别名)
POST _aliases { "actions": [ {"add": {"index": "l*", "alias": "f1"}} ] }
别名交换
POST _aliases { "actions": [ {"add": {"index": "l1", "alias": "a1"}}, {"remove_index":{"index":"a1"}} ] } # 就像删除a1别名
过滤器别名
1.自定义索引
2.插入数据
3.普通查询和根据别名查询
PUT l4 { "mappings": { "doc":{ "properties":{ "year":{ "type":"integer" }, "method":{ "type":"keyword" } } } } } PUT l4/doc/1 { "year":2019, "method":"GET" } PUT l4/doc/2 { "year":2018, "method":"POST" } PUT l4/doc/3 { "year":2019, "method":"POST" } POST _aliases { "actions": [ { "add": { "index": "l4", "alias": "a4", "filter": { "term": { "year": 2019 } } } } ] } GET l4/doc/_search GET a4/doc/_search
此时两种查询结果不同(带有过滤的只返回2019,而普通查询会全部返回)
与路由连用
简单实例
POST _aliases { "actions": [ { "add": { "index": "l4", "alias": "a4", "routing": "2" } } ] }
再列举一个
POST _aliases { "actions": [ { "add": { "index": "l4", "alias": "a4", "search_routing": "1,2", "index_routing": "1" } } ] }
GET a4/doc/_search?q=year:2019&routing=2 # 取交集2
写索引(如果多个索引指向一个别名,通过别名写索引,不指定es不知道)
POST _aliases { "actions": [ { "add": { "index": "l1", "alias": "a1", "is_write_index": true } }, { "add": { "index": "l2", "alias": "a1" } } ] }
添加单个别名
PUT {index}/_alias/{name}
PUT {index}/_alias/{name}?routing=user1
删除别名
DELETE l1/_alias/a1
DELETE l2/_aliases/a*
检索现有别名
GET l1/_alias/a* # 查询索引l1指向以a开头的所有别名 GET l1/_alias/* # 查询索引l1所有的别名
查询所有别名是a1
GET /_alias/a1
HEAD检测别名是否存在
GET _cat/aliases
HEAD _alias/a1
标签:search 名称 检索 last tin 命名 插入 div a*
原文地址:https://www.cnblogs.com/Alexephor/p/11413722.html