如何通过Java SDK获取Collection列表

40 阅读1分钟

本文介绍如何通过Java SDK获取所有已创建的Collection名称列表。


前提条件

接口定义

Java示例:

// class DashVectorClient

public Response<List<String>> list();

接口使用

说明

需要使用您的api-key替换示例中的YOUR_API_KEY、您的Cluster Endpoint替换示例中的YOUR_CLUSTER_ENDPOINT,代码才能正常运行。

Java示例:

import com.aliyun.dashvector.DashVectorClient;
import com.aliyun.dashvector.DashVectorCollection;
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");
      
        Response<List<String>> response = client.list();
      
        System.out.println(response);
        // example output:
        // {
        //     "code":0,
        //     "message":"",
        //     "requestId":"5de1a75e-2996-4496-a284-9b958dfdad53",
        //     "output":[
        //         "simple",
        //         "quickstart"
        //     ]
        // }
    }
}

入参描述

出参描述

说明

返回结果为Response<List<String>>对象,Response<List<String>>对象中可获取本次操作结果信息,如下表所示。

方法类型描述示例
getCode()int返回值,参考返回状态码说明0
getMessage()String返回消息success
getRequestId()String请求唯一id19215409-ea66-4db9-8764-26ce2eb5bb99
getOutput()List所有Collection名称列表['my_collection1', 'my_collection2']
isSuccess()Boolean判断请求是否成功true