AI Hints
Home›Elasticsearch Tutorial›Nested, Reindex and Aliases
Elasticsearch · Lesson 48 of 120

Aliases

A name that can move.

⏱ 2 min read▶ Video at 44:25🎓 Free
Watch this lesson in the Elasticsearch courseWatch on YouTube ↗Full Elasticsearch course

Your app searches an index called products. If you reindex into products v2, you'd have to change the app. An alias is a second name that points to an index, and can be moved in one step.

  • App uses one name
  • Data moves
  • Alias points the way

Swap an alias

Products v1 and v2 both exist, and the alias shop points at v1. One aliases request removes it from v1, and adds it to v2, at the same moment. Run it. The app keeps searching shop, and now gets v2.

Dev Tools Consoletext
POST _aliases?filter_path=acknowledged
{ "actions": [
  { "remove": { "index": "products_v1", "alias": "shop" } },
  { "add":    { "index": "products_v2", "alias": "shop" } } ] }

GET _cat/aliases/shop?h=alias,index
Output
# POST _aliases 200 OK
{"acknowledged": true}

# GET _cat/aliases/shop 200 OK
shop products_v2
Also uses _setup.http
PUT products_v1

PUT products_v2

POST _aliases
{ "actions": [ { "add": { "index": "products_v1", "alias": "shop" } } ] }

Why aliases matter

Apps should always use an alias, never a raw index name. Then you can reindex with no downtime. An alias can also point at several indexes, like all of this year's order indexes. And it can carry a filter, like only in stock products.

keyvalue
Apps usethe alias
Reindexswap, no downtime
Many indexessearch them together
Filtered aliasa saved filter

Summary

An alias is a movable name for one or more indexes. Swapping it is atomic, so apps never notice a reindex. Next, index templates.

Key takeaways
  • Alias
  • Atomic swap
  • No downtime
Next up: Index Templates — settings for new indexes