Get collection statistics

更新时间:
复制 MD 格式

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:

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.

PlaceholderDescription
YOUR_API_KEYAPI key for your DashVector cluster
YOUR_CLUSTER_ENDPOINTEndpoint of your DashVector cluster
Note

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

MethodReturn typeDescriptionExample
getCode()intStatus code. 0 indicates success. For a full list, see Status codes.0
getMessage()StringStatus message.success
getRequestId()StringUnique request identifier for troubleshooting.19215409-ea66-4db9-8764-26ce2eb5bb99
getOutput()CollectionStatsCollection statistics object. See the fields below.--
isSuccess()BooleanReturns 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.

FieldDescription
totalDocCountTotal number of documents in the collection.
indexCompletenessIndex build progress.
partitionsPer-partition statistics. Each key is a partition name, and each value contains the totalDocCount for that partition.