本文介紹如何通過Java SDK擷取已建立的Collection的狀態和Schema資訊。
前提條件
已建立Cluster:建立Cluster。
已獲得API-KEY:API-KEY管理。
已安裝最新版SDK:安裝DashVector SDK。
介面定義
Java
// class DashVectorClient
public Response<CollectionMeta> describe(String name);
使用樣本
需要使用您的api-key替換樣本中的YOUR_API_KEY、您的Cluster Endpoint替換樣本中的YOUR_CLUSTER_ENDPOINT,代碼才能正常運行。
本樣本需要參考建立Collection-使用樣本提前建立好名稱為
quickstart
的Collection。
Java
import com.aliyun.dashvector.DashVectorClient;
import com.aliyun.dashvector.common.DashVectorException;
import com.aliyun.dashvector.models.CollectionMeta;
import com.aliyun.dashvector.models.responses.Response;
public class Main {
public static void main(String[] args) throws DashVectorException {
DashVectorClient client = new DashVectorClient("YOUR_API_KEY", "YOUR_CLUSTER_ENDPOINT");
Response<CollectionMeta> response = client.describe("quickstart");
System.out.println(response);
// example output:
// {
// "code":0,
// "message":"",
// "requestId":"cb468965-d86b-405a-87a4-a596e61c1240",
// "output":{
// "name":"quickstart",
// "dimension":4,
// "dataType":"FLOAT",
// "metric":"dotproduct",
// "status":"SERVING",
// "fieldsSchema":{
// "name":"STRING",
// "weight":"FLOAT",
// "age":"INT",
// "id":"LONG"
// },
// "partitionStatus":{
// "default":"SERVING"
// }
// }
// }
}
}
入參描述
參數 | 類型 | 必填 | 預設值 | 說明 |
name | String | 是 | - | 已建立集合的名稱 |
出參描述
返回結果為Response<CollectionMeta>
對象,Response<CollectionMeta>
對象中可擷取本次操作結果資訊,如下表所示。
欄位 | 類型 | 描述 | 樣本 |
getCode() | int | 傳回值,參考返回狀態代碼說明 | 0 |
getMessage() | String | 返回訊息 | success |
getRequestId | String | 請求唯一id | 19215409-ea66-4db9-8764-26ce2eb5bb99 |
getOutput() | CollectionMeta |
| |
isSuccess() | Boolean | 判斷請求是否成功 | true |