您的位置:首页 > 其它

Elasticsearch模块功能之-索引别名(Index aliases )

2014-08-07 19:38 295 查看
Elasticsearch的API支持给索引起别名,有了别名之后可以像使用索引一样使用它。但不只是这些,一个别名可以映射多个索引,所以在需要经常指定多个索引查询的情况下,大可将所查询的索引起一个别名来查。别名也可以将索引查询的过滤条件包含在内,使用别名查询时可以查询索引的一个子集。

创建一个别名

curl -XPOST 'http://localhost:9200/_aliases'-d '
{
"actions" : [
{ "add" : { "index" : "test1","alias" : "alias1" } }
]
}'


上述将创建一个指向索引test1的别名alias1。

删除别名:

curl -XPOST 'http://localhost:9200/_aliases'-d '
{
"actions" : [
{ "remove" : { "index" : "test1","alias" : "alias1" } }
]
}'

上述将删除别名alias1.

重命名别名:

curl -XPOST 'http://localhost:9200/_aliases' -d '
{
"actions" : [
{ "remove" : { "index" : "test1", "alias" : "alias1" } },
{ "add" : { "index" : "test1", "alias" : "alias2" } }
]
}'

[/code]

创建映射多个索引的别名:

curl -XPOST 'http://localhost:9200/_aliases'-d '
{
"actions" : [
{ "add" : { "index" : "test1","alias" : "alias1" } },
{ "add" : { "index" : "test2","alias" : "alias1" } }
]
}'

上述创建的别名alias1映射索引test1和索引test2。

创建索引在索引创建期间:

curl -XPUT localhost:9200/logs_20142801 -d '{
"aliases" : {
"current_day" : {},
"2014" : {
"filter" : {
"term" : {"year": 2014 }
}
}
}
}'


查看索引是所有别名:

curl -XGET 'localhost:9200/users/_alias/*<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);"> </span>


查看具体别名:

curl -XGET 'localhost:9200/_alias/2013'


包含过滤条件的别名:

curl -XPOST 'http://localhost:9200/_aliases' -d '
{
"actions" : [
{
"add" : {
"index" : "test1",
"alias" : "alias2",
"filter" : { "term" : { "user" : "kimchy" } }
}
}
]
}'


上述的别名将映射到索引test1使用过滤条件之后的结果,类似数据库的视图。

【参考】:http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-aliases.html#indices-aliases
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: