An index exists with the same name as the alias – How to solve this Elasticsearch error

An index exists with the same name as the alias – How to solve this Elasticsearch error

Opster Team

February-21, Version: 1.7-8.0

To understand why an index exists with the same name as the alias and what you should do to correct the situation, we recommend you run the Elasticsearch Error Check-Up. It will analyze your ES deployment to pinpoint the cause of the issue and provide you with suitable actionable recommendations to resolve the issue. The tool is free and requires no installation.

Overview

This error message is Elasticsearch informing you that you tried to create an alias with the same name as an index that already exists. Since 7.14 it will also produce a similar error message if a data stream exists with the same name of the alias you are trying to create.

What it means

When you send a search request to Elasticsearch you usually(*) specify on which collection(s) of documents you want your search to run. You do that by calling the _search API on one of the following targets:

  • An index, which can also be specified as a comma separated list of indices and that also support * as a wildcard operator 
  • An alias, which will be translated to one or more indices
  • A data stream (since 7.9)
  • The special _all placeholder that stands for all indices

An alias is a convenient way to hide many indices and data streams behind a facade, so your application doesn’t have to know the names of every index and list them in the search request. You create an alias by simply giving it a name and a pattern of indices you want this alias to translate into:

POST _aliases
{
  "actions": [
    {
      "add": {
        "index": "house-sensors*",
        "alias": "house-sensors"
      }
    }
  ]
}

Since aliases, indices and data streams share the same namespace, Elasticsearch will produce an error if you try to create an alias with a name that collides with any of those other resource types:

PUT some-index/_doc/1
{
  "some_field": "some_value"
}
 
POST _aliases
{
  "actions": [
    {
      "add": {
        "index": "some-index*",
        "alias": "some-index"
      }
    }
  ]
}
 
Response:
 
{
  "error" : {
    "root_cause" : [
      {
        "type" : "invalid_alias_name_exception",
        "reason" : "Invalid alias name [some-index], an index exists with the same name as the alias",
        "index_uuid" : "K75RkLc6StWkkfjtyHbREQ",
        "index" : "some-index"
      }
    ],
    "type" : "invalid_alias_name_exception",
    "reason" : "Invalid alias name [some-index], an index exists with the same name as the alias",
    "index_uuid" : "K75RkLc6StWkkfjtyHbREQ",
    "index" : "some-index"
  },
  "status" : 400
}

If you are running at least Elasticsearch 7.14 the error message will be slightly different:

{
  "error" : {
    "root_cause" : [
      {
        "type" : "invalid_alias_name_exception",
        "reason" : "Invalid alias name [some-index], an index or data stream exists with the same name as the alias",
        "index_uuid" : "K75RkLc6StWkkfjtyHbREQ",
        "index" : "some-index"
      }
    ],
    "type" : "invalid_alias_name_exception",
    "reason" : "Invalid alias name [some-index], an index exists with the same name as the alias",
    "index_uuid" : "K75RkLc6StWkkfjtyHbREQ",
    "index" : "some-index"
  },
  "status" : 400
}

*The _search API actually allows you to send a search request without specifying against which indices you want your search to run. In that case the search request will consider all indices. 

How to resolve it

You should simply choose another alias name, or rename your indices so you can use that name for the alias.
You can use the _cat API to list all existing indices and aliases in your cluster:

GET _cat/indices
 
GET _cat/aliases

Log Context

Log”an index exists with the same name as the alias”classname  is AliasValidator.java We extracted the following from Elasticsearch source code for those seeking an in-depth context :

throw new IllegalArgumentException("index name is required");
  }
 
  IndexMetadata indexNamedSameAsAlias = indexLookup.apply(alias);
  if (indexNamedSameAsAlias != null) {
  throw new InvalidAliasNameException(indexNamedSameAsAlias.getIndex(); alias; "an index exists with the same name as the alias");
  }
  }
 
  void validateAliasStandalone(String alias; String indexRouting) {
  if (!Strings.hasText(alias)) {

 

Run the Check-Up to get a customized report like this:

Analyze your cluster