首页   快速返回

elasticsearch5.0索引别名     所属分类 elasticsearch
根据原文翻译整理
https://www.elastic.co/guide/en/elasticsearch/reference/5.0/indices-aliases.html


The index aliases API allow to alias an index with a name, 
with all APIs automatically converting the alias name to the actual index name. 
An alias can also be mapped to more than one index, and when specifying it, 
the alias will automatically expand to the aliases indices. 
An alias can also be associated with a filter that will automatically be applied when searching, 
and routing values. An alias cannot have the same name as an index.



索引别名API允许为索引建立别名,所有API都会自动将别名转换为实际的索引名称。
别名还可以映射到多个索引,当指定它时,别名将自动扩展到对应的索引。
别名还可以与筛选器关联,筛选器将在搜索和路由时自动应用。别名不能与索引重名。


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

add remove 

{ "add" : { "indices" : ["test1", "test2"], "alias" : "alias1" } }

{ "add" : { "index" : "test*", "alias" : "all_test_indices" } }
  
  

Aliases with filters provide an easy way to create different "views" of the same index. 
带过滤条件的别名  索引视图



POST /_aliases
{
    "actions" : [
        {
            "add" : {
                 "index" : "test1",
                 "alias" : "alias2",
                 "filter" : { "term" : { "user" : "kimchy" } }
            }
        }
    ]
}


Routing
It is possible to associate routing values with aliases. 
This feature can be used together with filtering aliases 
in order to avoid unnecessary shard operations.

The following command creates a new alias alias1 that points to index test. 
After alias1 is created, all operations with this alias 
are automatically modified to use value 1 for routing

与路由关联的别名
可以将路由与别名关联起来,这个特性可以与过滤别名一起使用,避免不必要的分片操作。


POST /_aliases
{
    "actions" : [
        {
            "add" : {
                 "index" : "test",
                 "alias" : "alias1",
                 "routing" : "1"
            }
        }
    ]
}

It’s also possible to specify different routing values for searching and indexing operations
为索引和搜索指定不同的路由值

这个的使用场景?  读写分离?


POST /_aliases
{
    "actions" : [
        {
            "add" : {
                 "index" : "test",
                 "alias" : "alias2",
                 "search_routing" : "1,2",
                 "index_routing" : "2"
            }
        }
    ]
}


Add a single alias
PUT /{index}/_alias/{name}

routing
An optional routing that can be associated with an alias.

filter
An optional filter that can be associated with an alias.

为别名指定路由和过滤条件

PUT /users
{
    "mappings" : {
        "user" : {
            "properties" : {
                "user_id" : {"type" : "integer"}
            }
        }
    }
}

PUT /users/_alias/user_12
{
    "routing" : "12",
    "filter" : {
        "term" : {
            "user_id" : 12
        }
    }
}

DELETE /{index}/_alias/{name}

GET /logs_20162801/_alias/*

All aliases with the name 2016 in any index:
GET /_alias/2016

All aliases that start with 20 in any index:
GET /_alias/20*


There is also a HEAD variant of the get indices aliases api to check if index aliases exist.

上一篇     下一篇
elasticsearch5.0磁盘使用优化

plantUML安装使用

通过男女关系形象解读大数据技术

elasticsearch5.0索引映射管理

elasticsearch5.0索引设置

elasticsearch5.0索引监控