alter_alias()
This operation reassigns the alias of one collection to another.
Request syntax
alter_alias(
collection_name: str,
alias: str,
timeout: float | None
) -> None
PARAMETERS:
collection_name (str) -
[REQUIRED]
The name of the target collection to reassign an alias to.
alias (str) -
[REQUIRED]
The alias of the collection. Note that the alias should exist beforehand.
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 Milvus, 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.
Below is an example of reassigning the alias of one collection to another:
Suppose there are two collections:
collection_1
andcollection_2
. There is also a collection alias namedbob
, which was originally assigned tocollection_1
:collection_1
's alias = [“bob”]collection_2
's alias = []
After calling
alter_alias("collection_2", “bob”)
:collection_1
's alias = []collection_2
's alias = [“bob”]
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 the specified alias does not exist.
Example
from pymilvus import MilvusClient
# 1. Create a milvus client
client = MilvusClient(
uri="http://localhost:19530",
token="root:Milvus"
)
# 2. Create two collections
client.create_collection(collection_name="test_collection_1", dimension=5)
client.create_collection(collection_name="test_collection_2", dimension=5)
# 3. Create an alias for the collection
client.create_alias(collection_name="test_collection_1", alias="test")
# 4. Reassign the alias to the other collection
client.alter_alias(collection_name="test_collection_2", alias="test")