Retrieve statistics for a DashVector collection, including the total document count, index build progress, and per-partition breakdowns.
Prerequisites
Before you begin, make sure that you have:
An API key
The DashVector SDK (latest version)
API definition
// DashVectorClient
public Response<CollectionStats> stats();This method takes no request parameters and returns a Response<CollectionStats> object containing the collection-level statistics.
Example
The following example retrieves statistics for a collection named quickstart. Before running the code, replace the placeholders with your actual values.
| Placeholder | Description |
|---|---|
YOUR_API_KEY | API key for your DashVector cluster |
YOUR_CLUSTER_ENDPOINT | Endpoint of your DashVector cluster |
Create the quickstart collection before running this example. For instructions, see the "Example" section in Create a collection.
import com.aliyun.dashvector.DashVectorClient;
import com.aliyun.dashvector.DashVectorCollection;
import com.aliyun.dashvector.models.CollectionStats;
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");
// Get a handle to the target collection
DashVectorCollection collection = client.get("quickstart");
// Retrieve collection statistics
Response<CollectionStats> response = collection.stats();
System.out.println(response);
}
}Sample output:
{
"code": 0,
"message": "Success",
"requestId": "84b801f9-7545-4f9e-b480-713d6c4d9393",
"output": {
"totalDocCount": 1,
"indexCompleteness": 1,
"partitions": {
"default": {
"totalDocCount": 1
}
}
}
}Response parameters
The stats() method returns a Response<CollectionStats> object.
Response wrapper
| Method | Return type | Description | Example |
|---|---|---|---|
getCode() | int | Status code. 0 indicates success. For a full list, see Status codes. | 0 |
getMessage() | String | Status message. | success |
getRequestId() | String | Unique request identifier for troubleshooting. | 19215409-ea66-4db9-8764-26ce2eb5bb99 |
getOutput() | CollectionStats | Collection statistics object. See the fields below. | -- |
isSuccess() | Boolean | Returns true if the request succeeded. | true |
CollectionStats fields
The getOutput() method returns a CollectionStats object with the following fields. For the full type definition, see CollectionStats.
| Field | Description |
|---|---|
totalDocCount | Total number of documents in the collection. |
indexCompleteness | Index build progress. |
partitions | Per-partition statistics. Each key is a partition name, and each value contains the totalDocCount for that partition. |