You need to enable JavaScript to run this app.
文档中心
向量数据库VikingDB

向量数据库VikingDB

复制全文
下载 pdf
数据(Data)
deleteData
复制全文
下载 pdf
deleteData

概述

deleteData 用于在指定的 Collection 中删除数据。使用 ids 按主键删除时单次最多删除 100 条;使用 delAll=true 时删除全部数据,不受 100 条限制。

方法定义
public DataApiResponse<DeleteDataResult> deleteData(DeleteDataRequest request)
            throws ApiClientException, VectorApiException

请求参数

参数名

类型

必选

备注

resourceId

String

至少填写一个

资源 ID;与 collectionName 至少传入一个,同时传入时优先使用 resourceId。

collectionName

String

至少填写一个

Collection 名称;未传 resourceId 时必填。

ids

List[Object]

与 delAll 至少填写一个

删除数据的主键列表(主键为 int64 或 string),最多 100 条。与 delAll=true 至少满足一个;同时传入时按 ids 删除。
注意:

  • 若为请求参数非法(4xx类型),则会全部失败。

delAll

Boolean

与 ids 至少填写一个

为 true 时删除所有数据,默认为 false。与 ids 同时传入时按 ids 删除;逻辑库不支持 delAll=true。
此接口删除所有数据,并不能立刻同步到索引,因此在一段时间内(5 分钟左右),索引内仍可检索到数据。

返回参数

Java 调用执行上面的任务,执行成功无返回信息。

示例

运行示例前,请完成以下准备:

  • 在 Java 项目中引入对应版本的 VikingDB SDK,并将示例放入可执行的 main 方法后编译运行。
  • AK/SK 在火山引擎控制台“密钥管理”中创建;Host 和 Region 取自地域和访问域名。请按代码的参数或环境变量读取方式完成配置。
  • Collection、Index 名称从 VikingDB 控制台对应资源详情获取;Task ID 使用创建或查询任务接口返回的 ID。请将 <YOUR_...> 占位符替换为真实值。
  • 若示例包含 TOS 路径,请从 TOS 控制台确认桶名和对象路径,并替换为真实的 <YOUR_BUCKET_NAME>/<YOUR_TOS_PATH>。

请求参数

package org.example.newsubproduct.data.data;


import com.volcengine.vikingdb.runtime.core.ClientConfig;
import com.volcengine.vikingdb.runtime.core.auth.AuthWithAkSk;
import com.volcengine.vikingdb.runtime.enums.Scheme;
import com.volcengine.vikingdb.runtime.exception.VectorApiException;
import com.volcengine.vikingdb.runtime.vector.model.request.*;
import com.volcengine.vikingdb.runtime.vector.model.response.*;
import com.volcengine.vikingdb.runtime.vector.service.VectorService;


import java.util.Arrays;


public class DeleteData {

    public static void main(String[] args) {
        VectorService vectorService = null;
        try {
            vectorService = new VectorService(
                    Scheme.HTTPS,
                    "api-vikingdb.vikingdb.cn-beijing.volces.com", // 填写向量库数据面v2的域名  https://www.volcengine.com/docs/84313/1792715
                    "cn-beijing",
                    new AuthWithAkSk(System.getenv("AK"), System.getenv("SK")),
                    ClientConfig.builder().build()
            );
        } catch (Exception e) {
            System.err.println("Client initialization failed: " + e.getMessage());
            e.printStackTrace();
            return;
        }

        DeleteDataRequest request = DeleteDataRequest.builder()
                .collectionName("<YOUR_COLLECTION_NAME>") // 替换为您的集合名称
                .ids(Arrays.asList(1, 2, 3))
                .build();

        try {
            DataApiResponse<DeleteDataResult> response = vectorService.deleteData(request);
            System.out.println("request success:");
            System.out.println(response);
        } catch (VectorApiException vectorApiException) {
            System.err.println("request vectorApiException:");
            System.out.println("apiName: " + vectorApiException.getApiName());
            System.out.println("httpStatusCode: " + vectorApiException.getHttpStatusCode());
            System.out.println("code: " + vectorApiException.getCode());
            System.out.println("message: " + vectorApiException.getMessage());
            System.out.println("requestId: " + vectorApiException.getRequestId());
            System.out.println("responseContext: " + vectorApiException.getResponseContext().getBody());
        } catch (Exception e) {
            System.err.println("request exception, message : " + e.getMessage());
            e.printStackTrace();
        }
    }
}

使用说明修正

删除成功时没有额外业务数据,但 SDK 仍返回通用响应对象。应检查其中的 requestId/RequestId(请求唯一标识)和状态或错误信息;“无返回信息”仅指没有删除结果明细。

最近更新时间:2026.09.08 12:02:54
这个页面对您有帮助吗?
有用
有用
无用
无用