Elasticsearch Alias

Elasticsearch Alias

Last Update: July 2020

Have you tried our Elasticsearch Check-Up ? (no installation required) get personalized recommendations that can prevent errors and improve your search and indexing speed

Alias in Elasticsearch

In Elasticsearch, an alias is a secondary name to refer to one or more indices. Aliases can be created and removed dynamically using _aliases REST endpoint.

What it is used for

Aliases are used for multiple purposes such as to search across more than one index with a single name, perform the reindexing process with zero downtime and query data based on predefined filters.

Examples

Creating an alias on a single index:

POST /_aliases?pretty
{
  "actions": [
    {
      "add": {
        "index": "index_1",
        "alias": "alias_1"
      }
    }
  ]
}

Creating the same alias on more than one index:

POST /_aliases?pretty
{
  "actions": [
    {
      "add": {
        "index": "index_1",
        "alias": "alias_1"
      }
    },
    {
      "add": {
        "index": "index_2",
        "alias": "alias_1"
      }
    }
  ]
}

Creating a filter-based alias:

POST /_aliases?pretty
{
  "actions": [
    {
      "add": {
        "index": "index_1",
        "alias": "alias_2",
        "filter": {
          "term": {
            "organization": "opster"
          }
        }
      }
    }
  ]
}

Listing out all of the available aliases in an Elasticsearch cluster:

GET _cat/aliases

Removing an alias:

POST /_aliases?pretty
{
  "actions": [
    {
      "remove": {
        "index": "index_2",
        "alias": "alias_1"
      }
    }
  ]
}
Notes
  • An Alias cannot be used for the indexing process if it points to more than one index. If attempted, Elasticsearch will throw an exception.
  • Deleting an alias does not delete the actual index.
Common Problems
  • Since a single alias can be attached to multiple indices, it is important to keep in mind that querying an alias will send the query against all the associated indices and this can impact the search performance and high resource utilization.

About Opster

Opster takes a different approach to Elasticsearch operation - Opster pro-actively troubleshoots, optimizes, automates and assists in what's needed to run Elasticsearch smoothly in production.


« Back to Index