What is an alias in Elasticsearch and how does it help with reindexing?
Understand Elasticsearch aliases, how they decouple apps from index names, and how an atomic alias swap enables zero-downtime reindexing.
Expected Interview Answer
An alias in Elasticsearch is a secondary, stable name that points to one or more indices, letting applications query and write through the alias instead of a concrete index name. It helps with reindexing because you can build a new index in the background, then atomically switch the alias from the old index to the new one, so clients keep using the same alias name with zero downtime and no code changes.
Applications talk to a logical name like orders rather than a physical index like orders-2026-07; the alias decouples the two. During a reindex you copy documents into orders-2026-08, verify it, then use the aliases API's add/remove actions in a single atomic request to repoint orders. Aliases can also carry a filter and routing, and a write alias marks exactly one index as the write target when the alias spans several indices.
- Zero-downtime reindexing via an atomic alias swap
- Applications reference a stable name, never a versioned index
- Filtered aliases expose a subset of documents as a virtual index
- One alias can fan reads across many indices for a unified view
- A designated write index keeps ingestion unambiguous
AI Mentor Explanation
An alias is like the role 'opening batter' on a team sheet: fans and the captain refer to the role, while the actual player filling it can change between matches. To swap players you simply reassign the role, and the batting order keeps working unchanged. Reindexing is the substitution — the new player warms up in the nets first, then takes the role in one clean switch mid-series.
Step-by-Step Explanation
Step 1
Point apps at the alias
Have clients read and write through a stable alias name (e.g. orders) rather than a concrete index like orders-v1.
Step 2
Create the new index
Define orders-v2 with the updated mapping or settings you need for the migration.
Step 3
Reindex the data
Use the _reindex API to copy documents from orders-v1 into orders-v2 and verify counts and sampling.
Step 4
Swap atomically
Call POST /_aliases with a remove of orders-v1 and add of orders-v2 in one request so the switch is instantaneous.
Step 5
Retire the old index
Once traffic is confirmed on orders-v2, delete orders-v1 to reclaim storage.
What Interviewer Expects
- Defines an alias as a stable pointer to one or more indices
- Explains the atomic add/remove swap in a single _aliases call
- Knows filtered and routing aliases
- Understands the single write index requirement for write aliases
- Connects aliases to zero-downtime reindexing workflows
Common Mistakes
- Hardcoding the physical index name in application code
- Doing remove then add in separate calls, causing a gap
- Writing through an alias that spans indices with no write index set
- Confusing an alias with an actual copy of the data
- Forgetting to update the mapping in the new index before reindexing
Best Answer (HR Friendly)
“An alias is a stable nickname for an index in Elasticsearch. Because apps use the nickname, you can quietly build an improved copy of the data behind the scenes and then flip the nickname to it in an instant, so users never see downtime during upgrades.”
Code Example
POST /_aliases
{
"actions": [
{ "remove": { "index": "orders-v1", "alias": "orders" } },
{ "add": { "index": "orders-v2", "alias": "orders", "is_write_index": true } }
]
}Follow-up Questions
- What is a filtered alias and when is it useful?
- How does is_write_index behave when an alias spans multiple indices?
- How does the _reindex API handle very large indices?
- How do aliases support blue-green index deployments?
- What happens to in-flight requests during an alias swap?
MCQ Practice
1. What is an Elasticsearch alias?
An alias is a logical name that resolves to one or more concrete indices, decoupling clients from physical index names.
2. Why perform remove and add in a single _aliases request?
Combining remove and add in one request swaps the target atomically, so no request ever sees the alias unassigned.
3. When an alias spans several indices, writes require what?
A write alias must designate a single write index so Elasticsearch knows unambiguously where indexing should go.
Flash Cards
What is an alias? — A stable secondary name that points to one or more indices, decoupling apps from physical index names.
How do aliases enable zero-downtime reindex? — Build a new index, then atomically remove the old and add the new alias target in one _aliases call.
What is a filtered alias? — An alias with a query filter that exposes only a subset of documents as a virtual index.
What is is_write_index? — The flag marking the single index that receives writes when an alias spans multiple indices.
Continue Learning
Related Interview Questions
What is mapping in Elasticsearch and why does it matter?
medium
How does Elasticsearch handle nested objects and the nested data type?
hard
What is the difference between a term query and a match query in Elasticsearch?
medium
What is analysis in Elasticsearch and how do analyzers, tokenizers, and filters work?
medium