Create a partition
This topic describes how to create a partition in a DashVector collection using the Java SDK.
Prerequisites
Before you begin, make sure that you have:
API definition
// class DashVectorCollection
public Response<Void> createPartition(String name, Integer timeout);Request parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| name | String | Yes | - | The name of the partition to create. |
| timeout | Integer | No | null | Controls synchronous or asynchronous behavior. See the following table for details. |
Timeout behavior
| Value | Mode | Behavior |
|---|---|---|
null | Synchronous | Blocks until the partition is created, then returns. |
-1 | Asynchronous | The method works in asynchronous mode. |
>= 0 | Synchronous | Blocks for up to the specified duration. Returns a timeout error if the partition is not created within this period. |
Response parameters
The method returns a Response<Void> object with the following methods:
| Method | Return type | Description | Example |
|---|---|---|---|
getCode() | int | Status code. For more information, see Status codes. | 0 |
getMessage() | String | Response message. | success |
getRequestId() | String | Unique request ID. | 19215409-ea66-4db9-8764-26ce2eb5bb99 |
isSuccess() | Boolean | Whether the operation succeeded. | true |
Example
Note
Before running this example, replace YOUR_API_KEY with your API key and YOUR_CLUSTER_ENDPOINT with your cluster endpoint. You also need a collection named quickstart. For details, see the "Example" section in Create a collection.
import com.aliyun.dashvector.DashVectorClient;
import com.aliyun.dashvector.DashVectorCollection;
import com.aliyun.dashvector.common.DashVectorException;
import com.aliyun.dashvector.models.responses.Response;
public class Main {
public static void main(String[] args) throws DashVectorException {
// 1. Connect to the cluster
DashVectorClient client = new DashVectorClient("YOUR_API_KEY", "YOUR_CLUSTER_ENDPOINT");
// 2. Get the target collection
DashVectorCollection collection = client.get("quickstart");
// 3. Create a partition named "shoes"
Response<Void> response = collection.createPartition("shoes");
// 4. Verify the result
if (response.isSuccess()) {
System.out.println("createPartition success");
}
}
}