-
操作别名的两个方法:
_alias:单个操作
_aliases:多个操作,原子性的操作
-
创建别名
curl -XPUT 'localhost:9200/dm_v1/_alias/dm'
curl -XPOST 'http://localhost:9200/_aliases' -d '
{
"actions" : [
{ "add" : { "index" : "dm_v1", "alias" : "dm_alias" } }
]
}'
-
删除别名
curl -XPOST 'http://localhost:9200/_aliases' -d '
{
"actions" : [
{ "remove" : { "index" : "dm_v1", "alias" : "dm_alias" } }
]
}'
curl -XDELETE 'localhost:9200/dm_v1/_alias/dm_alias'
-
删除别名的同时添加别名到新的索引,该操作时原子性的,不用担心存在别名没有指向任何索引的瞬间
Renaming an alias is a simple remove then add operation within the same API. This operation is atomic, no need to worry about a short period of time where the alias does not point to an index:
curl -XPOST 'http://localhost:9200/_aliases' -d '
{
"actions" : [
{ "remove" : { "index" : "dm_v1", "alias" : "dm" } },
{ "add" : { "index" : "dm_v2", "alias" : "dm" } }
]
}'
-
查询别名
通过别名查询所指向的索引:
curl -XGET 'localhost:9200/_alias/dm'
curl -XGET 'localhost:9200/_alias/dm*'
查询指向该索引下的所有别名:
curl -XGET 'localhost:9200/dm_v2/_alias/*'
-
也可以通过head检测别名是否存在
curl -XHEAD -i 'localhost:9200/_alias/dm'
curl -XHEAD -i 'localhost:9200/_alias/dm*'
curl -XHEAD -i 'localhost:9200/dm_v2/_alias/*'
-
转载
elasticsearch 别名alias
最新推荐文章于 2023-10-25 15:27:43 发布