createAlias()
A MilvusClient interface. This method creates an alias for a collection. Alias cannot be duplicated. The same alias cannot be assigned to different collections. Instead, you can specify multiple aliases for each collection.
R<RpcStatus> createAlias(CreateAliasParam requestParam);
CreateAliasParam
Use the CreateAliasParam.Builder
to construct a CreateAliasParam
object.
import io.milvus.param.CreateAliasParam;
CreateAliasParam.Builder builder = CreateAliasParam.newBuilder();
Methods of CreateAliasParam.Builder
:
Method |
Description |
Parameters |
---|---|---|
withCollectionName( |
Sets the target collection name. |
collectionName: The name of the target collection to create an alias for. |
withDatabaseName(String databaseName) |
Sets the database name. database name can be null for default database. |
databaseName: The database name. |
withAlias(String alias) |
Sets the collection alias. |
alias: The alias of the target collection. |
build() |
Constructs a CreateAliasParam object. |
N/A |
CreateAliasParam.Builder.build()
can throw the following exceptions:
- ParamException: error if the parameter is invalid.
Returns
This method catches all the exceptions and returns an R<RpcStatus>
object.
If the API fails on the server side, it returns the error code and message from the server.
If the API fails by RPC exception, it returns
R.Status.Unknown
and the error message of the exception.If the API succeeds, it returns
R.Status.Success
.
Example
import io.milvus.param.*;
CreateAliasParam param = CreateAliasParam.newBuilder()
.withCollectionName(COLLECTION_NAME)
.withAlias("alias1")
.build();
R<RpcStatus> response = client.createAlias(param)
if (response.getStatus() != R.Status.Success.getCode()) {
System.out.println(response.getMessage());
}