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

刪除Doc

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

本文介紹如何通過Java SDK,根據id或id列表刪除Collection中已存在的Doc。

說明

如果指定id不存在,則刪除對應Doc的操作無效。

前提條件

介面定義

Java
// 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提前插入部分資料。

Java
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

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