本文介紹如何通過Java SDK擷取已建立的Collection的統計資訊,如Doc數等。
前提條件
已建立Cluster:建立Cluster。
已獲得API-KEY:API-KEY管理。
已安裝最新版SDK:安裝DashVector SDK。
介面定義
Java
// class DashVectorClient
public Response<CollectionStats> stats();
使用樣本
需要使用您的api-key替換樣本中的YOUR_API_KEY、您的Cluster Endpoint替換樣本中的YOUR_CLUSTER_ENDPOINT,代碼才能正常運行。
本樣本需要參考建立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 |
| |
isSuccess() | Boolean | 判斷請求是否成功 | true |