Elasticsearch alias别名管理小结

Elasticsearch alias别名管理小结

By:授客 QQ:1033553122 

 

建创测试数据 1

创建别名 2

移除别名 3

创建测试数据 4

批量操作 5

1. 5

2. 把多个索引添加到一个别名中 6

3. 使用通配符 8

 

测试环境:

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

 

Elasticsearch <wbr>alias别名管理小结 

 

移除别名

POST /_aliases

{

   "actions": [

      {

         "remove": {

            "index": "test1_index",

            "alias": "test1_index_alias"

         }

      }

   ]

}

 

验证

POST /test1_index_alias/_search

 

Elasticsearch <wbr>alias别名管理小结 

 

 

创建测试数据

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

Elasticsearch <wbr>alias别名管理小结

 

 

 

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"

         }

      }

   ]

}

 

验证

 

 

Elasticsearch <wbr>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

 

转载于:https://www.cnblogs.com/shouke/p/10157524.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值