Elasticsearch alias别名管理小结
Elasticsearch alias别名管理小结
By:授客 QQ:1033553122
测试环境:
Win elasticsearch-5.4.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"
}
}
]
}
POST /_aliases
{
"actions": [
{
"remove": {
"index": "test1_index",
"alias": "test_index_alias"
}
},
{
"add": {
"index": "test2_index",
"alias": "test_index_alias"
}
}
]
}
POST /test_index_alias/_search
重置环境
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"
}
}
]
}
把所有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
作者:授客
微信/QQ:1033553122
全国软件测试QQ交流群:7156436
Git地址:https://gitee.com/ishouke
友情提示:限于时间仓促,文中可能存在错误,欢迎指正、评论!
作者五行缺钱,如果觉得文章对您有帮助,请扫描下边的二维码打赏作者,金额随意,您的支持将是我继续创作的源动力,打赏后如有任何疑问,请联系我!!!
微信打赏
支付宝打赏 全国软件测试交流QQ群