Index aliases let you use a simple name to point to one or more indexes. This helps you search or update data without worrying about the real index names.
0
0
Index aliases in Elasticsearch
Introduction
You want to switch between different versions of data without changing your app.
You want to search across multiple indexes as if they were one.
You want to hide the real index names from users or apps.
You want to add or remove indexes from a group easily.
You want to update data in one index while reading from another.
Syntax
Elasticsearch
POST /_aliases
{
"actions": [
{ "add": { "index": "index_name", "alias": "alias_name" } },
{ "remove": { "index": "old_index", "alias": "alias_name" } }
]
}You use the _aliases API to add or remove aliases.
Each action can add or remove an alias for a specific index.
Examples
This adds an alias named
products pointing to the index products_v1.Elasticsearch
POST /_aliases
{
"actions": [
{ "add": { "index": "products_v1", "alias": "products" } }
]
}This switches the alias
products from products_v1 to products_v2.Elasticsearch
POST /_aliases
{
"actions": [
{ "remove": { "index": "products_v1", "alias": "products" } },
{ "add": { "index": "products_v2", "alias": "products" } }
]
}This makes the alias
logs point to two indexes, so searching logs searches both.Elasticsearch
POST /_aliases
{
"actions": [
{ "add": { "index": "logs_2023_01", "alias": "logs" } },
{ "add": { "index": "logs_2023_02", "alias": "logs" } }
]
}Sample Program
This example adds an alias library for the index library_2023. Then it searches the alias library to get all documents.
Elasticsearch
POST /_aliases
{
"actions": [
{ "add": { "index": "library_2023", "alias": "library" } }
]
}
GET /library/_search
{
"query": {
"match_all": {}
}
}OutputSuccess
Important Notes
Aliases can point to multiple indexes at once.
You can use aliases to simplify index management and avoid downtime.
Aliases can also have filters or routing to control what data is seen.
Summary
Index aliases let you use easy names instead of real index names.
You can add, remove, or switch aliases anytime without changing your app.
Aliases can point to one or many indexes for flexible searching.