主要针对1.5版本,主要参考自官网资料,可以理解为一个翻译+实践+扩充的版本
在endpoint中操作
增加别名
能够通过如下的方式添加
PUT /{index}/_alias/{name}
- index为别名指向的index,可以是 * | _all | glob pattern | name1, name2, …
- name为别名的名字,这项必须
- routing 可选,别名绑定的路由
- filter 可选,别名绑定的过滤器
也可以使用复数个_aliases
例子:
curl -XPUT 'localhost:9200/logs_201305/_alias/2013'
有路由和过滤器的例子
首先创建一个有user_id字段的index
curl -XPUT 'localhost:9200/users' -d '{
"mappings" : {
"user" : {
"properties" : {
"user_id" : {"type" : "integer"}
}
}
}
}'
然后添加带路由和过滤器的alias
curl -XPUT 'localhost:9200/users/_alias/user_12' -d '{
"routing" : "12",
"filter" : {
"term" : {
"user_id" : 12
}
}
}'
当然,路由也可以拆开为index_routing和search_routing
curl -XPUT 'localhost:9200/users/_alias/user_12' -d '{
"index_routing" : "12",
"search_routing" : "11",
"filter" : {
"term" : {
"user_id" : 12
}
}
}'
在index创建期间创建别名
可以在创建index期间创建别名
curl -XPUT localhost:9200/logs_20142801 -d '{
"mappings" : {
"type" : {
"properties" : {
"year" : {"type" : "integer"}
}
}
},
"aliases" : {
"current_day" : {},
"2014" : {
"filter" : {
"term" : {"year" : 2014 }
},
"routing