本文由簡體中文內容自動轉碼而成。阿里雲不保證此自動轉碼的準確性、完整性及時效性。本文内容請以簡體中文版本為準。

統計Collection

更新時間:2024-07-13 00:20

本文介紹如何通過Java SDK擷取已建立的Collection的統計資訊,如Doc數等。

前提條件

介面定義

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
        //             }
        //         }
        //     }
        // }
    }
}

入參描述

出參描述

說明

返回結果為Response<CollectionStats>對象,Response<CollectionStats>對象中可擷取本次操作結果資訊,如下表所示。

方法

類型

描述

樣本

getCode()

int

傳回值,參考返回狀態代碼說明

0

getMessage()

String

返回訊息

success

getRequestId()

String

請求唯一id

19215409-ea66-4db9-8764-26ce2eb5bb99

getOutput()

CollectionStats

參考CollectionStats

{
  "totalDocCount":1,
  "indexCompleteness":1,
  "partitions":{
    "default":{
      "totalDocCount":1
    }
  }
}

isSuccess()

Boolean

判斷請求是否成功

true

  • 本頁導讀 (1, M)
  • 前提條件
  • 介面定義
  • 使用樣本
  • 入參描述
  • 出參描述
文檔反饋