Search

Aliases

Aliases let you create alternative names for your search indices. This is useful for zero-downtime reindexing — you can build a new index, then atomically swap the alias to point to it.


Adding an Alias

The SEARCH.ALIASADD command creates a new alias or updates an existing alias to point to a different index.

Returns 1 if a new alias was created, or 2 if an existing alias was updated to point to a new index.

// Top-level: create or update an aliasconst result = await redis.search.alias.add({  indexName: "products-v2",  alias: "products",});// Via index methodconst result2 = await index.addAlias({ alias: "products" });
# Top-level: create or update an aliasresult = redis.search.alias.add(index_name="products-v2", alias="products")# Via index methodresult = index.add_alias(alias="products")
# Create or update an aliasSEARCH.ALIASADD products products-v2

A common pattern is to use aliases for zero-downtime reindexing:

// 1. Create a new index with updated schemaconst productsV2 = await redis.search.createIndex({  name: "products-v2",  dataType: "json",  prefix: "product:",  schema,});// 2. Wait for indexing to completeawait productsV2.waitIndexing();// 3. Swap the alias to point to the new indexawait redis.search.alias.add({  indexName: "products-v2",  alias: "products",});// 4. Drop the old indexconst oldIndex = redis.search.index({ name: "products-v1" });await oldIndex.drop();
# 1. Create a new index with updated schemaproducts_v2 = redis.search.create_index(    name="products-v2",    data_type="json",    prefix="product:",    schema=schema,)# 2. Wait for indexing to completeproducts_v2.wait_indexing()# 3. Swap the alias to point to the new indexredis.search.alias.add(index_name="products-v2", alias="products")# 4. Drop the old indexold_index = redis.search.index(name="products-v1")old_index.drop()
# 1. Create new indexSEARCH.CREATE products-v2 ON JSON PREFIX 1 product: SCHEMA name TEXT price F64 FAST# 2. Wait for indexingSEARCH.WAITINDEXING products-v2# 3. Swap aliasSEARCH.ALIASADD products products-v2# 4. Drop old indexSEARCH.DROP products-v1

Deleting an Alias

The SEARCH.ALIASDEL command removes an alias.

Returns 1 if the alias was deleted, or 0 if the alias was not found.

const result = await redis.search.alias.delete({ alias: "products" });
result = redis.search.alias.delete(alias="products")
SEARCH.ALIASDEL products

Listing Aliases

The SEARCH.LISTALIASES command returns all aliases and the indices they point to.

const aliases = await redis.search.alias.list();// → { "products": "products-v2", "users": "users-v1" }
aliases = redis.search.alias.list()# → {"products": "products-v2", "users": "users-v1"}
SEARCH.LISTALIASES# → [["products", "products-v2"], ["users", "users-v1"]]
Loading search…