List partitions

更新时间:
复制 MD 格式

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

Note
  1. Replace <your-api-key> and <your-cluster-endpoint> with your actual values.

  2. This example assumes a collection named quickstart already 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

getCode()

int

Status code. 0 indicates success. For all status codes, see Status codes.

0

getMessage()

String

Status message.

success

getRequestId()

String

Unique request ID for troubleshooting.

19215409-ea66-4db9-8764-26ce2eb5bb99

getOutput()

List<String>

Names of all partitions in the collection.

["shoes", "default"]

isSuccess()

Boolean

Whether the operation succeeded.

true