按别名删除索引

Delete index by alias name

使用 Elasticsearch,我可以通过名称删除索引:

DELETE my_index
{}

但是我不能通过别名删除它:

DELETE my_index_alias
{}

错误是:

{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "The provided expression [my_index_alias] matches an alias, specify the corresponding concrete indices instead."
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "The provided expression [my_index_alias] matches an alias, specify the corresponding concrete indices instead."
  },
  "status": 400
}

有没有办法通过别名删除索引?

我相信你想要实现的目标是不可能的。目前,ElasticSearch DELETE API 支持以下内容:

  1. 您可以删除索引

curl -XDELETE 'http://localhost:9200/{indexname}'

删除 {indexname} 当且仅当 {indexname} 是 具体索引。

或 2. 改为删除别名

curl -XDELETE 'http://localhost:9200/_alias/{aliasname}'

删除 {aliasname} 当且仅当 {aliasname} 是 索引别名。

您提到的错误表明您使用语法 DELETE whatever_you_put_here 删除的内容实际上是语法或查询 删除索引 并建议用户如果他们正在寻找要删除indexes,则无法通过删除别名来完成。

当您创建别名时,例如myalias 并且您将示例索引 myindex 关联到它,在删除索引 myindex 后,您的别名 myalias 也会被删除。

然而,当您创建一个别名并将两个索引关联到它时,您需要删除两个索引才能使您的别名成为删除。

Elasticsearch 中不存在空的 alias,您无法创建它。

请注意,您可以通过执行以下查询来检查您拥有的别名列表

GET /_alias

现在,如果您只想删除 indexalias,您可以使用下面的 DELETE 查询将其删除。

DELETE myindex/_alias/myalias

请注意,如果您有两个索引引用相同的别名,那么别名将继续存在,直到您对两个索引执行上述 DELETE 操作。

is there a way to delete an index using its alias

至于上面的查询,我认为不可能,也没有意义。