deleteData 用于在指定的 Collection 中删除数据。使用 ids 按主键删除时单次最多删除 100 条;使用 delAll=true 时删除全部数据,不受 100 条限制。
public DataApiResponse<DeleteDataResult> deleteData(DeleteDataRequest request) throws ApiClientException, VectorApiException
参数名 | 类型 | 必选 | 备注 |
|---|---|---|---|
resourceId | String | 至少填写一个 | 资源 ID;与 |
collectionName | String | 至少填写一个 | Collection 名称;未传 |
ids | List[Object] | 与 delAll 至少填写一个 | 删除数据的主键列表(主键为 int64 或 string),最多 100 条。与
|
delAll | Boolean | 与 ids 至少填写一个 | 为 true 时删除所有数据,默认为 false。与 |
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(请求唯一标识)和状态或错误信息;“无返回信息”仅指没有删除结果明细。