create_alias()
This operation creates an alias for an existing collection.
Request Syntax
create_alias(
collection_name: str,
alias: str,
using: str,
timeout: float | None
)
PARAMETERS:
collection_name (str) -
[REQUIRED]
The name of the collection to create an alias for.
alias (str) -
[REQUIRED]
The alias of the collection. Before this operation, ensure that the alias does not already exist. If it does, exceptions will occur.
what is a collection alias?
A collection alias is an additional name for a collection. Collection aliases are useful when you want to switch your application to a new collection without any changes to your code.
In MilvusZilliz Cloud, a collection alias is a globally unique identifier. One alias can only be assigned to exactly one collection. Conversely, a collection can have multiple aliases.
Suppose there is one collection:
collection_1
. You can assign two different aliases (bob
andtom
) to this collection by callingcreate_alias("collection_1", “bob”)
andcreate_alias("collection_1", “tom”)
.using (str) -
The alias of the employed connection.
The default value is default, indicating that this operation employs the default connection.
timeout (float | None)
The timeout duration for this operation. Setting this to None indicates that this operation timeouts when any response arrives or any error occurs.
RETURN TYPE:
NoneType
RETURNS:
None
EXCEPTIONS:
MilvusException
This exception will be raised when any error occurs during this operation, especially when you set
alias
to an existing alias.BaseException
This exception will be raised when this operation fails.
Examples
from pymilvus import connections, Collection, utility
# Connection to localhost:19530
connections.connect()
# Get an existing collection
collection_1 = Collection("collection_1")
# Create an alias for collection_1
utility.create_alias(collection_name="collection_1", alias="bob")
# List aliases for the collection
utility.list_aliases(collection_name="collection_1") # ['bob']
# Create another alias for collection_1
utility.create_alias(collection_name="collection_1", alias="tom")
# List aliases for the collection
utility.list_aliases(collection_name="collection_1") # ['bob', 'tom']