Retrieve all partition names in a DashVector collection by using the Java SDK.
Prerequisites
Before you begin, make sure that you have:
API reference
// DashVectorCollection class
public Response<List<String>> listPartitions();This method takes no parameters and returns a Response<List<String>> with the names of all partitions in the collection.
Example
Replace
<your-api-key>and<your-cluster-endpoint>with your actual values.This example assumes a collection named
quickstartalready exists. To create one, see the "Example" section of the Create a collection topic.
import com.aliyun.dashvector.DashVectorClient;
import com.aliyun.dashvector.DashVectorCollection;
import com.aliyun.dashvector.common.DashVectorException;
import com.aliyun.dashvector.models.responses.Response;
import java.util.List;
public class Main {
public static void main(String[] args) throws DashVectorException {
// Initialize the client with your API key and cluster endpoint
DashVectorClient client = new DashVectorClient("<your-api-key>", "<your-cluster-endpoint>");
// Get the target collection
DashVectorCollection collection = client.get("quickstart");
// List all partitions in the collection
Response<List<String>> response = collection.listPartitions();
System.out.println(response);
// Example output:
// {"code":0,"message":"","requestId":"d72a4f14-ff9a-4e39-89d4-ce023d34d37f","output":["default","shoes"]}
}
}Response
The method returns a Response<List<String>> object with the following methods:
Method | Return type | Description | Example |
|
| Status code. |
|
|
| Status message. |
|
|
| Unique request ID for troubleshooting. |
|
|
| Names of all partitions in the collection. |
|
|
| Whether the operation succeeded. |
|