Get a collection

更新时间: 2026-03-10 21:33:40

Retrieve an existing collection by name to perform operations such as inserting documents, searching for documents, and managing partitions.

Prerequisites

Before you begin, make sure that you have:

API definition

// DashVectorClient
public DashVectorCollection get(String name);

Request parameters

ParameterTypeRequiredDefault valueDescription
nameStringYes-The name of an existing collection.

Example

Note

Replace <your-api-key> and <your-cluster-endpoint> with your actual values before running this code. We recommend storing credentials in environment variables to avoid hardcoding sensitive information. This example uses a collection named quickstart. To create one, see the example in Create a collection.

import com.aliyun.dashvector.DashVectorClient;
import com.aliyun.dashvector.DashVectorCollection;
import com.aliyun.dashvector.common.DashVectorException;

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>");

        // Retrieve the collection by name
        DashVectorCollection collection = client.get("quickstart");

        // Verify the operation succeeded
        assert collection.isSuccess();
    }
}

Response parameters

The get method returns a DashVectorCollection object with the following methods:

MethodTypeDescriptionExample
getCode()intStatus code. For more information, see Status codes.0
getMessage()StringResponse messagesuccess
getRequestId()StringUnique request ID19215409-ea66-4db9-8764-26ce2eb5bb99
getName()StringCollection namecomplex
getCollectionMeta()CollectionMetaCollection metadata. For more information, see CollectionMeta.See the following example
isSuccess()BooleanWhether the operation succeededtrue

CollectionMeta example

{
  "name": "quickstart",
  "dimension": 4,
  "dataType": "INT",
  "metric": "dotproduct",
  "status": "SERVING",
  "fieldsSchema": {
    "name": "STRING",
    "weight": "FLOAT",
    "age": "INT"
  },
  "partitionStatus": {
    "default": "SERVING"
  }
}

What's next

上一篇: Get collection details 下一篇: List collections