This topic describes how to manage collection aliases. Milvus supports specifying a unique alias for a collection.
A collection alias is globally unique, hence you cannot assign the same alias to different collections. However, you can assign multiple aliases to one collection.
When interacting with Milvus using Python code, you have the flexibility to choose between PyMilvus and MilvusClient (new). For more information, refer to Python SDK .
The following example is based on the alias publication
.
Specify an alias for a collection.
from pymilvus import utility
utility.create_alias (
collection_name = "book" ,
alias = "publication"
)
await milvusClient.createAlias({
collection_name: "book" ,
alias : "publication" ,
});
err = milvusClient.CreateAlias (
context.Background (),
"book" ,
"publication" ,
)
if err != nil {
log.Fatal ("failed to create alias:" , err.Error ())
}
milvusClient.createAlias (
CreateAliasParam .newBuilder ()
.withCollectionName ("book" )
.withAlias ("publication" )
.build ()
);
create alias -c book -a publication
curl -X 'POST' \
'http://localhost:9091/api/v1/alias' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"collection_name": "book",
"alias":"publication"
}'
{}
Parameter
Description
collection_name
Name of the collection to create alias on.
alias
Collection alias to create.
Parameter
Description
collection_name
Name of the collection to create alias on.
alias
Collection alias to create.
Parameter
Description
CollectionName
Name of the collection to create alias on.
Alias
Collection alias to create.
Option
Description
-c
Name of the collection to create alias on.
-a
Collection alias to create.
-A (Optional)
Flag to transfer the alias to a specified collection.
Parameter
Description
collection_name
Name of the collection to create alias on.
alias
Collection alias to create.
Drop a specified alias.
from pymilvus import utility
utility.drop_alias (alias = "publication" )
await milvusClient.dropAlias({
alias : "publication" ,
});
err = milvusClient.DropAlias (
context.Background (),
"publication" ,
)
if err != nil {
log.Fatal ("failed to drop alias:" , err.Error ())
}
milvusClient.dropAlias (
DropAliasParam .newBuilder ()
.withAlias ("publication" )
.build ()
);
delete alias -a publication
curl -X 'DELETE' \
'http://localhost:9091/api/v1/alias' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"alias":"publication"
}'
{}
Parameter
Description
alias
Collection alias to drop.
Parameter
Description
alias
Collection alias to drop.
Parameter
Description
Alias
Collection alias to drop.
Option
Description
-a
Collection alias to drop.
Parameter
Description
alias
Collection alias to drop.
Alter an existing alias to another collection. The following example is based on the situation that the alias publication
was originally created for another collection.
from pymilvus import utility
utility.alter_alias (
collection_name = "book" ,
alias = "publication"
)
await milvusClient.alterAlias({
collection_name: "book" ,
alias : "publication" ,
});
err = milvusClient.AlterAlias (
context.Background (),
"book" ,
"publication" ,
)
if err != nil {
log.Fatal ("failed to alter alias:" , err.Error ())
}
milvusClient.alterAlias (
AlterAliasParam .newBuilder ()
.withCollectionName ("book" )
.withAlias ("publication" )
.build ()
);
create alias -c book -A -a publication
curl -X 'PATCH' \
'http://localhost:9091/api/v1/alias' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"collection_name": "book",
"alias":"publication"
}'
Parameter
Description
collection_name
Name of the collection to alter alias to.
alias
Collection alias to alter.
Parameter
Description
collection_name
Name of the collection to alter alias to.
alias
Collection alias to alter.
Parameter
Description
CollectionName
Name of the collection to alter alias to.
Alias
Collection alias to alter.
Option
Description
-c
Name of the collection to alter alias to.
-a
Collection alias to alter.
-A
Flag to transfer the alias to a specified collection.
Parameter
Description
collection_name
Name of the collection to alter alias to.
alias
Collection alias to alter.
Feature Maximum limit
Length of an alias 255 characters
Learn more basic operations of Milvus: