Collection aliases
v1.32Collection aliases allow you to create alternative names for your collections. This is useful for migrating between collections without downtime, A/B testing, or providing more convenient names for collections. An alias acts as a reference to a collection - when you query and manage objects using an alias name, Weaviate automatically routes the request to the target collection.
Weaviate automatically routes alias requests to the target collection for object-related operations. You can use aliases wherever collection names are required for:
- Managing objects: Create, batch import, read, update and delete objects through collection aliases.
- Querying objects: Fetch objects and perform searches (vector, keyword, hybrid, image, generative/RAG) and aggregations through aliases.
Create an alias
To create an alias, specify the alias name and the target collection it should point to.
If a snippet doesn't work or you have feedback, please open a GitHub issue.
# Create a collection first
client.collections.create(
name="Articles",
vector_config=wvc.config.Configure.Vectors.self_provided(),
properties=[
wvc.config.Property(name="title", data_type=wvc.config.DataType.TEXT),
wvc.config.Property(name="content", data_type=wvc.config.DataType.TEXT),
],
)
# Create an alias pointing to the collection
client.alias.create(alias_name="ArticlesAlias", target_collection="Articles")
- An alias name must be unique and cannot match any existing collection or alias name
- Multiple aliases can point to the same collection
- Aliases can only be used instead of collection names in object-related operations (managing objects and querying)
List all aliases
Retrieve all aliases in your Weaviate instance.
If a snippet doesn't work or you have feedback, please open a GitHub issue.
# Get all aliases in the instance
all_aliases = client.alias.list_all()
for alias_name, alias_info in all_aliases.items():
print(f"Alias: {alias_info.alias} -> Collection: {alias_info.collection}")
List aliases for a specific collection
Get all aliases that point to a specific collection.
If a snippet doesn't work or you have feedback, please open a GitHub issue.
# Get all aliases pointing to a specific collection
collection_aliases = client.alias.list_all(collection="Articles")
for alias_name, alias_info in collection_aliases.items():
print(f"Alias pointing to Articles: {alias_info.alias}")
Get alias details
Retrieve information about a specific alias.
If a snippet doesn't work or you have feedback, please open a GitHub issue.
# Get information about a specific alias
alias_info = client.alias.get(alias_name="ArticlesAlias")
if alias_info:
print(f"Alias: {alias_info.alias}")
print(f"Target collection: {alias_info.collection}")
Update an alias
Change the target collection that an alias points to. This operation is atomic and provides instant switching between collections.
If a snippet doesn't work or you have feedback, please open a GitHub issue.
# Create a new collection for migration
client.collections.create(
name="ArticlesV2",
vector_config=wvc.config.Configure.Vectors.self_provided(),
properties=[
wvc.config.Property(name="title", data_type=wvc.config.DataType.TEXT),
wvc.config.Property(name="content", data_type=wvc.config.DataType.TEXT),
wvc.config.Property(
name="author", data_type=wvc.config.DataType.TEXT
), # New field
],
)
# Update the alias to point to the new collection
success = client.alias.update(
alias_name="ArticlesAlias", new_target_collection="ArticlesV2"
)
if success:
print("Alias updated successfully")
Updating an alias is particularly useful for migrations:
- Create a new collection with updated collection definition
- Import data into the new collection
- Update the alias to point to the new collection
- Continue to use the alias - all queries to it are now directed to the new collection
For a code example on how to perform migrations, visit the Tutorial: Migrating collections with aliases
Delete an alias
Remove an alias. This only deletes the alias pointer, not the underlying collection.
If a snippet doesn't work or you have feedback, please open a GitHub issue.
# Delete an alias (the underlying collection remains)
client.alias.delete(alias_name="ArticlesAlias")
- Deleting a collection does not automatically delete aliases pointing to it
Using aliases in operations
Once created, aliases can be used instead of collection names in all object-related operations, like data import and querying.
If a snippet doesn't work or you have feedback, please open a GitHub issue.
# Ensure the Articles collection exists (it might have been deleted in previous examples)
client.collections.create(
name="Articles",
vector_config=wvc.config.Configure.Vectors.self_provided(),
properties=[
wvc.config.Property(name="title", data_type=wvc.config.DataType.TEXT),
wvc.config.Property(name="content", data_type=wvc.config.DataType.TEXT),
],
)
# Use the alias just like a collection name
articles = client.collections.use("ArticlesAlias")
# Insert data using the alias
articles.data.insert(
{
"title": "Using Aliases in Weaviate",
"content": "Aliases make collection management easier...",
}
)
# Query using the alias
results = articles.query.fetch_objects(limit=5)
for obj in results.objects:
print(f"Found: {obj.properties['title']}")
Further resources
- Manage collections: Basic operations
- References: Collection definition
-
API References: REST: Aliases
Questions and feedback
If you have any questions or feedback, let us know in the user forum.
