Elasticsearchalias别名管理小结
测试环境:
Win elasticsearch-5.4.1
1. 别名管理
建创测试数据
PUT test1_index
POST test1_index/doctype/1
{
"name":"shouke",
"addr":"深圳"
}
POST test1_index/doctype/2
{
"name":"shou ke",
"addr":"深圳"
}
POST test1_index/doctype/_search
创建别名
POST /_aliases
{
"actions": [
{
"add": {
"index": "test1_index",
"alias": "test1_index_alias"
}
}
]
}
说明:index 为要创建别名的“源索引”,alias别名
搜索验证
POST /test1_index_alias/_search
移除别名
POST /_aliases
{
"actions": [
{
"remove": {
"index": "test1_index",
"alias": "test1_index_alias"
}
}
]
}
验证
POST /test1_index_alias/_search
创建测试数据
PUT /test2_index
POST test2_index/doctype/1
{
"name":"shouke",
"addr":"福建"
}
POST test2_index/doctype/2
{
"name":"shou ke",
"addr":"福建"
}
POST /_aliases
{
"actions": [
{
"add": {
"index": "test1_index",
"alias": "test_index_alias"
}
}
]
}
批量操作
例1.
POST /_aliases
{
"actions": [
{
"remove": {
"index": "test1_index",
"alias": "test_index_alias"
}
},
{
"add": {
"index": "test2_index",
"alias": "test_index_alias"
}
}
]
}
POST /test_index_alias/_search
例2. 把多个索引添加到一个别名中
重置环境
POST /_aliases
{
"actions": [
{
"remove": {
"index": "test1_index",
"alias": "test_index_alias"
}
},
{
"remove": {
"index": "test2_index",
"alias": "test_index_alias"
}
}
]
}
添加别名
POST /_aliases
{
"actions": [
{
"add": {
"index": "test1_index",
"alias": "test_index_alias"
}
},
{
"add": {
"index": "test2_index",
"alias": "test_index_alias"
}
}
]
}
验证
等效做法
POST /_aliases
{
"actions": [
{
"add": {
"indices": [
"test1_index",
"test2_index"
],
"alias": "test_index_alias"
}
}
]
}
例3. 使用通配符
把所有test开头的索引都添加到别名all_test_indices中
POST /_aliases
{
"actions": [
{
"add": {
"index": "test*",
"alias": "all_test_indices"
}
}
]
}
更多资料参考:
https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html
https://www.elastic.co/guide/en/elasticsearch/reference/current/indices.html#alias-management