索引别名可用于实现零停机维护,一般别名的使用场景有两种:1、将多个索引指向同一别名,多用于日志数据;2、利用别名创建不同的视图,多用于业务数据
1 将多个索引指向同一个别名
PUT movies-2019/_doc/1
{
"name":"the matrix",
"rating":5
}
PUT movies-2018/_doc/1
{
"name":"Speed",
"rating":3
}
POST _aliases
{
"actions": [
{
"add": {
"index": "movies-2019",
"alias": "movies-latest"
}
},
{
"add": {
"index": "movies-2019",
"alias": "movies-latest"
}
}
]
}
#支持针对单个索引和多个索引进行操作
POST movies-latest/_search
{
"query": {
"match_all": {}
}
}
2 使用alias创建不同查询的视图
PUT movies-2019/_doc/1
{
"name":"the matrix",
"rating":5
}
PUT movies-2019/_doc/1
{
"name":"Speed",
"rating":3
}
POST _aliases
{
"actions": [
{
"add": {
"index": "movies-2019",
"alias": "movies-lastest-highrate",
"filter": {
"range": {
"rating": {
"gte": 4
}
}
}
}
}
]
}
POST movies-lastest-highrate/_search
{
"query": {
"match_all": {}
}
}
文章转载自lin在路上,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




