使用 Iterator 导出数据
Zilliz Cloud 支持您将您的数据完整导出。本文将使用 Iterator 接口演示如何从 Zilliz Cloud Collection 中导出数据。
概述
Milvus 的 Python 和 Java SDK 提供了一组 Iterator API,可按需迭代指定 Collection 中的数据。关于这些接口的具体情况,可查看使用 Iterators。
使用 Iterator 可获得如下收益:
-
简化操作:免去复杂的
offset
和limit
参数设置。 -
提高效率:按需获取数据,享受更快速的数据检索体验。
-
一致性:通过布尔过滤确保每次迭代都能维持数据集的一致大小。
您可使用 Iterator 接口全量或部分导出指定 Collection 中的数据。
📘说明
此功能支持与 Milvus v2.3.x 及之后版本兼容的 Zilliz Cloud 集群。
准备工作
在如下步骤中,我们使用快速建表方法创建了一个 Collection, 并向其添加了 10,000 条随机数据。
创建 Collection
- Python
- Java
from pymilvus import MilvusClient
CLUSTER_ENDPOINT = "YOUR_CLUSTER_ENDPOINT"
TOKEN = "YOUR_CLUSTER_TOKEN"
# 1. Set up a Milvus client
client = MilvusClient(
uri=CLUSTER_ENDPOINT,
token=TOKEN
)
# 2. Create a collection
client.create_collection(
collection_name="quick_setup",
dimension=5,
)
import io.milvus.client.MilvusServiceClient;
import io.milvus.param.ConnectParam;
import io.milvus.param.highlevel.collection.CreateSimpleCollectionParam;
String CLUSTER_ENDPOINT = "YOUR_CLUSTER_ENDPOINT";
String TOKEN = "YOUR_CLUSTER_TOKEN";
// 1. Connect to Milvus server
ConnectParam connectParam = ConnectParam.newBuilder()
.withUri(CLUSTER_ENDPOINT)
.withToken(TOKEN)
.build();
MilvusServiceClient client = new MilvusServiceClient(connectParam);
// 2. Create a collection
CreateSimpleCollectionParam createCollectionParam = CreateSimpleCollectionParam.newBuilder()
.withCollectionName("quick_setup")
.withDimension(5)
.build();
client.createCollection(createCollectionParam);