Index aliases in Elasticsearch - Time & Space Complexity
When using index aliases in Elasticsearch, it's important to understand how the system handles queries through these aliases.
We want to know how the time to find data changes as the amount of data or number of aliases grows.
Analyze the time complexity of this alias usage in Elasticsearch.
POST /_aliases
{
"actions": [
{ "add": { "index": "products_v1", "alias": "products" } },
{ "add": { "index": "products_v2", "alias": "products" } }
]
}
GET /products/_search
{
"query": { "match_all": {} }
}
This code adds two indices under one alias and then searches using the alias.
Look at what repeats when searching through an alias.
- Primary operation: Searching each index behind the alias.
- How many times: Once per index linked to the alias.
As the number of indices behind an alias grows, the search runs on each one.
| Input Size (number of indices) | Approx. Operations |
|---|---|
| 1 | 1 search operation |
| 10 | 10 search operations |
| 100 | 100 search operations |
Pattern observation: The work grows directly with the number of indices behind the alias.
Time Complexity: O(n)
This means the search time increases linearly with the number of indices the alias points to.
[X] Wrong: "Searching through an alias is always as fast as searching one index."
[OK] Correct: Because the alias can point to many indices, Elasticsearch must search each one, so time grows with the number of indices.
Understanding how aliases affect search time helps you explain real-world Elasticsearch performance and design choices clearly and confidently.
"What if the alias pointed to indices with very different sizes? How would that affect the overall search time complexity?"