文档

删除Doc

更新时间:

本文介绍如何通过Java SDK,根据id或id列表删除Collection中已存在的Doc。

说明

如果指定id不存在,则删除对应Doc的操作无效。

前提条件

接口定义

// class DashVectorCollection

// 同步接口
public Response<List<DocOpResult>> delete(DeleteDocRequest deleteDocRequest);

// 异步接口
public ListenableFuture<Response<List<DocOpResult>>> deleteAsync(DeleteDocRequest deleteDocRequest);

使用示例

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

  2. 本示例需要参考新建Collection-使用示例提前创建好名称为quickstart的Collection,并参考插入Doc提前插入部分数据。

import com.aliyun.dashvector.DashVectorClient;
import com.aliyun.dashvector.DashVectorCollection;
import com.aliyun.dashvector.common.DashVectorException;
import com.aliyun.dashvector.models.requests.DeleteDocRequest;
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");
        DashVectorCollection collection = client.get("quickstart");

        // 构建 DeleteDocRequest
        DeleteDocRequest request = DeleteDocRequest.builder()
            .id("1")
            .build();

        // 发送删除Doc请求
        Response<List<DocOpResult>> response = collection.delete(request);
    }
}

入参描述

通过DeleteDocRequestBuilder构造DeleteDocRequest对象,其可用方法如下表所示:

方法

必填

默认值

描述

ids(List<String> ids)

-

文档主键列表

id(String id)

-

partition(String partition)

default

分区名称

deleteAll(Boolean deleteAll)

false

是否清除分区内的全部数据。当传入true时,要求ids为空

build()

-

-

构造DeleteDocRequest对象

出参描述

说明

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

方法

类型

描述

示例

getCode()

int

返回值,参考返回状态码说明

0

getMessage()

String

返回消息

success

getRequestId()

String

请求唯一id

19215409-ea66-4db9-8764-26ce2eb5bb99

getOutput()

List<DocOpResult>

返回删除的结果

isSuccess()

Boolean

判断请求是否成功

true

  • 本页导读 (0)
文档反馈