0
点赞
收藏
分享

微信扫一扫

如何通过Java SDK统计Collection


本文介绍如何通过Java SDK获取已创建的Collection的统计信息,如Doc数等。

前提条件

  • 已创建Cluster:创建Cluster。
  • 已获得API-KEY:API-KEY管理。
  • 已安装最新版SDK:安装DashVector SDK。

接口定义

Java示例:

// class DashVectorClient

public Response<CollectionStats> stats();

使用示例

说明

  1. 需要使用您的api-key替换示例中的YOUR_API_KEY、您的Cluster Endpoint替换示例中的YOUR_CLUSTER_ENDPOINT,代码才能正常运行。
  2. 本示例需要参考新建Collection-使用示例提前创建好名称为quickstart的Collection。

Java示例:

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 {
        DashVectorClient client = new DashVectorClient("YOUR_API_KEY", "YOUR_CLUSTER_ENDPOINT");

        DashVectorCollection collection = client.get("quickstart");
        Response<CollectionStats> response = collection.stats();
        
      	System.out.println(response);
      	// example output:
        // {
        //     "code":0,
        //     "message":"Success",
        //     "requestId":"84b801f9-7545-4f9e-b480-713d6c4d9393",
        //     "output":{
        //         "totalDocCount":1,
        //         "indexCompleteness":1,
        //         "partitions":{
        //             "default":{
        //                 "totalDocCount":1
        //             }
        //         }
        //     }
        // }
    }
}


举报

相关推荐

0 条评论