Elasticsearch & Lucene (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)
Reindexing Patterns and Zero-Downtime Index Migrations: Index Aliases and the `_reindex` API.
senior LevelMost AskedCode ExampleDatabases & SQLHTTP & REST APIs
In Simple Words: Because Lucene inverted indexes are immutable, changing field data types or analyzers requires creating a new index and reindexing documents:
- Index Aliases: Never point applications directly to a raw index name (
orders_v1). Always query through a logical alias (orders). - Zero-Downtime Reindex Workflow:
- Create new index
orders_v2with updated mapping. - Run asynchronous reindexing:
POST _reindex?wait_for_completion=false. - Atomically swap alias from v1 to v2:
json
POST /_aliases { "actions": [ { "remove": { "index": "orders_v1", "alias": "orders" } }, { "add": { "index": "orders_v2", "alias": "orders" } } ] } - Delete legacy index
orders_v1once validated.
- Create new index