如何在Elasticsearch中删除中文索引

问题现象

因为某种特殊的原因,发现在es集群中出现了中文名称的索引,通过_cat API查询结果如下:

GET /_cat/indices/?v

health status index   uuid                   pri rep docs.count docs.deleted store.size pri.store.size
green  open   rcp-b   nqTIHs6-SSG0K-Pa7guIIA   5   0          1            0        4kb            4kb
green  open   .kibana T4aQP8DTT72aS0qrg7k_-w   1   0         19            3     64.6kb         64.6kb
red  open   测试索引中文 T4aQP8DTT99aS0qrg7k_-w   5   1         19            3     64.6kb         64.6kb

直接用DELETE API 删除报错

DELETE /测试索引中文

{
  "error": {
    "root_cause": [
      {
        "type": "index_not_found_exception",
        "reason": "no such index",
        "index_uuid": "_na_",
        "resource.type": "index_or_alias",
        "resource.id": "KÕ\"\u0015-‡",
        "index": "KÕ\"\u0015-‡"
      }
    ],
    "type": "index_not_found_exception",
    "reason": "no such index",
    "index_uuid": "_na_",
    "resource.type": "index_or_alias",
    "resource.id": "KÕ\"\u0015-‡",
    "index": "KÕ\"\u0015-‡"
  },
  "status": 404
}

如何删除这个"测试索引中文" 的索引呢 ?

思路就是用别名API(_alias)将这个中文索引,别名成英文,然后再用DELETE API删除

POST /_aliases
{
    "actions" : [
        { "add" : { "index" : "测试索引中文", "alias" : "testcn" } }
    ]
}

DELETE /testcn

posted @ 2019-07-08 18:14  wangzhen3798  阅读(917)  评论(0编辑  收藏  举报