コレクションの変更
コレクションの名前変更や設定変更が行えます。このページでは、コレクションを変更する方法について説明します。
コレクション名の変更
コレクションの名前は、次の手順で変更できます。
- Python
- Java
- NodeJS
- Go
- cURL
- C++
from pymilvus import MilvusClient
client = MilvusClient(
uri="YOUR_CLUSTER_ENDPOINT",
token="YOUR_CLUSTER_TOKEN"
)
client.rename_collection(
old_name="my_collection",
new_name="my_new_collection"
)
import io.milvus.v2.service.collection.request.RenameCollectionReq;
import io.milvus.v2.client.ConnectConfig;
import io.milvus.v2.client.MilvusClientV2;
String CLUSTER_ENDPOINT = "YOUR_CLUSTER_ENDPOINT";
String TOKEN = "YOUR_CLUSTER_TOKEN";
// 1. Connect to Milvus server
ConnectConfig connectConfig = ConnectConfig.builder()
.uri(CLUSTER_ENDPOINT)
.token(TOKEN)
.build();
MilvusClientV2 client = new MilvusClientV2(connectConfig);
RenameCollectionReq renameCollectionReq = RenameCollectionReq.builder()
.collectionName("my_collection")
.newCollectionName("my_new_collection")
.build();
client.renameCollection(renameCollectionReq);
import { MilvusClient, DataType } from "@zilliz/milvus2-sdk-node";
const address = "YOUR_CLUSTER_ENDPOINT";
const token = "YOUR_CLUSTER_TOKEN";
const client = new MilvusClient({address, token});
const res = await client.renameCollection({
oldName: "my_collection",
newName: "my_new_collection"
});
import (
"context"
"fmt"
"github.com/milvus-io/milvus/client/v2/milvusclient"
)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
milvusAddr := "YOUR_CLUSTER_ENDPOINT"
token := "YOUR_CLUSTER_TOKEN"
client, err := milvusclient.New(ctx, &milvusclient.ClientConfig{
Address: milvusAddr,
APIKey: token,
})
if err != nil {
fmt.Println(err.Error())
// handle error
}
defer client.Close(ctx)
err = client.RenameCollection(ctx, milvusclient.NewRenameCollectionOption("my_collection", "my_new_collection"))
if err != nil {
fmt.Println(err.Error())
// handle error
}
export CLUSTER_ENDPOINT="YOUR_CLUSTER_ENDPOINT"
export TOKEN="YOUR_CLUSTER_TOKEN"
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/collections/rename" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
--header "Request-Timeout: 10" \
-d '{
"collectionName": "my_collection",
"newCollectionName": "my_new_collection"
}'
#include "milvus/MilvusClientV2.h"
auto client = milvus::MilvusClientV2::Create();
milvus::ConnectParam connect_param{"YOUR_CLUSTER_ENDPOINT", "YOUR_CLUSTER_TOKEN"};
auto status = client->Connect(connect_param);
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}
status = client->RenameCollection(milvus::RenameCollectionRequest()
.WithCollectionName("my_collection")
.WithNewCollectionName("my_new_collection"));
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}
コレクションプロパティの設定
コレクションの作成後でも、コレクションレベルのプロパティを変更できます。
このセクションに記載されているプロパティは、すべてマネージドコレクションにのみ適用されます。
サポートされるプロパティ
プロパティ | 説明 |
|---|---|
| コレクションのデータを一定期間後に削除する必要がある場合は、Time-To-Live (TTL) を秒単位で設定することを検討してください。TTL が期限切れになると、Zilliz Cloud はコレクションからすべてのエンティティを削除します。 削除は非同期で行われるため、削除が完了する前でも検索やクエリを実行できます。 詳細については、コレクションレベルの TTL の設定 を参照してください。 |
| 各エンティティの絶対有効期限タイムスタンプを格納する 詳細については、エンティティレベルの TTL の設定 を参照してください。 |
| メモリマッピング (Mmap) を使用すると、ディスク上の大きなファイルへ直接メモリアクセスできるため、Zilliz Cloud はインデックスとデータをメモリとハードドライブの両方に格納できます。これにより、アクセス頻度に基づいたデータ配置の最適化が可能になり、検索パフォーマンスを維持したままコレクションのストレージ容量を拡張できます。 Zilliz Cloud は、クラスターに対して グローバル mmap 設定 を実装しています。特定のフィールドまたはそのインデックスに対して設定を変更することも可能です。 詳細については、mmap の使用 を参照してください。 |
| Partition Key Isolation を有効にすると、Zilliz Cloud は Partition Key の値に基づいてエンティティをグループ化し、各グループに個別のインデックスを作成します。検索リクエストを受信すると、Zilliz Cloud はフィルタリング条件で指定された Partition Key の値に基づいて対象インデックスを特定し、検索範囲をそのインデックス内のエンティティに限定します。これにより、無関係なエンティティのスキャンが回避され、検索パフォーマンスが大幅に向上します。 詳細については、Partition Key Isolation の使用 を参照してください。 |
| 動的フィールドを有効にせずに作成されたコレクションで、動的フィールドを有効にします。有効化後は、元のスキーマで定義されていないフィールドを持つエンティティを挿入できるようになります。詳細については、動的フィールド を参照してください。 |
| コレクションで AutoID が有効になっている場合に、ユーザー指定の主キー値をコレクションが受け入れるかどうかを指定します。
|
| 時間に関連する操作、特に |
例 1: コレクションレベルの TTL を設定する
次のコードスニペットは、コレクションの TTL を設定する方法を示しています。
- Python
- Java
- NodeJS
- Go
- cURL
- C++
from pymilvus import MilvusClient
client.alter_collection_properties(
collection_name="my_collection",
properties={"collection.ttl.seconds": 60}
)
import io.milvus.param.Constant;
import io.milvus.v2.service.collection.request.AlterCollectionPropertiesReq;
AlterCollectionPropertiesReq alterCollectionReq = AlterCollectionPropertiesReq.builder()
.collectionName("my_collection")
.property(Constant.TTL_SECONDS, "60")
.build();
client.alterCollectionProperties(alterCollectionReq);
res = await client.alterCollection({
collection_name: "my_collection",
properties: {
"collection.ttl.seconds": 60
}
})
err = client.AlterCollectionProperties(ctx, milvusclient.NewAlterCollectionPropertiesOption("my_collection").WithProperty(common.CollectionTTLConfigKey, 60))
if err != nil {
fmt.Println(err.Error())
// handle error
}
export CLUSTER_ENDPOINT="YOUR_CLUSTER_ENDPOINT"
export TOKEN="YOUR_CLUSTER_TOKEN"
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/collections/alter_properties" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
--header "Request-Timeout: 10" \
-d '{
"collectionName": "my_collection",
"properties": {
"collection.ttl.seconds": 60
}
}'
auto status = client->AlterCollectionProperties(milvus::AlterCollectionPropertiesRequest()
.WithCollectionName("my_collection")
.AddProperty(milvus::COLLECTION_TTL_SECONDS, "60"));
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}
例 2: エンティティレベルの TTL を設定する | PRIVATE
次のコードスニペットでは、既存の TIMESTAMPTZ フィールド(expire_at)をエンティティレベルの TTL フィールドとして指定します。コレクションには同名の TIMESTAMPTZ フィールドがすでに存在している必要があり、collection.ttl.seconds は設定されていない必要があります。これら 2 つの TTL モードは相互に排他です。
エンティティレベルの TTL の一連のワークフロー(スキーマ設定、挿入、クエリ、更新、削除)については、「エンティティレベルの TTL を設定する」を参照してください。
- Python
- Java
- NodeJS
- Go
- cURL
- C++
from pymilvus import MilvusClient
client.alter_collection_properties(
collection_name="my_collection",
properties={"ttl_field": "expire_at"}
)
// java
// nodejs
// go
# restful
// cpp
例 3: mmap を有効にする
次のコードスニペットは、mmap を有効にする方法を示しています。
- Python
- Java
- NodeJS
- Go
- cURL
- C++
from pymilvus import MilvusClient
client.alter_collection_properties(
collection_name="my_collection",
properties={"mmap.enabled": True}
)
AlterCollectionPropertiesReq alterCollectionReq = AlterCollectionPropertiesReq.builder()
.collectionName("my_collection")
.property(Constant.MMAP_ENABLED, "True")
.build();
client.alterCollectionProperties(alterCollectionReq);
await client.alterCollectionProperties({
collection_name: "my_collection",
properties: {
"mmap.enabled": true
}
});
err = client.AlterCollectionProperties(ctx, milvusclient.NewAlterCollectionPropertiesOption("my_collection").WithProperty(common.MmapEnabledKey, true))
if err != nil {
fmt.Println(err.Error())
// handle error
}
# restful
curl -X POST "YOUR_CLUSTER_ENDPOINT/v2/vectordb/collections/alter_properties" \
-H "Content-Type: application/json" \
-d '{
"collectionName": "my_collection",
"properties": {
"mmap.enabled": "true"
}
}'
auto status = client->AlterCollectionProperties(milvus::AlterCollectionPropertiesRequest()
.WithCollectionName("my_collection")
.AddProperty(milvus::MMAP_ENABLED, "true"));
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}
例 4: パーティションキーを有効にする
次のコードスニペットは、パーティションキーを有効にする方法を示しています。
- Python
- Java
- NodeJS
- Go
- cURL
- C++
from pymilvus import MilvusClient
client.alter_collection_properties(
collection_name="my_collection",
properties={"partitionkey.isolation": True}
)
AlterCollectionPropertiesReq alterCollectionReq = AlterCollectionPropertiesReq.builder()
.collectionName("my_collection")
.property("partitionkey.isolation", "True")
.build();
client.alterCollectionProperties(alterCollectionReq);
await client.alterCollectionProperties({
collection_name: "my_collection",
properties: {
"partitionkey.isolation": true
}
});
err = client.AlterCollectionProperties(ctx, milvusclient.NewAlterCollectionPropertiesOption("my_collection").WithProperty(common.PartitionKeyIsolationKey, true))
if err != nil {
fmt.Println(err.Error())
// handle error
}
# restful
curl -X POST "YOUR_CLUSTER_ENDPOINT/v2/vectordb/collections/alter_properties" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <token>" \
-d '{
"collectionName": "my_collection",
"properties": {
"partitionkey.isolation": "true"
}
}'
auto status = client->AlterCollectionProperties(milvus::AlterCollectionPropertiesRequest()
.WithCollectionName("my_collection")
.AddProperty("partitionkey.isolation", "true"));
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}
例 5: 動的フィールドを有効にする
次のコードスニペットは、動的フィールドを有効にする方法を示しています。
- Python
- Java
- NodeJS
- Go
- cURL
- C++
from pymilvus import MilvusClient
client.alter_collection_properties(
collection_name="my_collection",
properties={"dynamicfield.enabled": True}
)
AlterCollectionPropertiesReq alterCollectionReq = AlterCollectionPropertiesReq.builder()
.collectionName("my_collection")
.property("dynamicfield.enabled", "True")
.build();
client.alterCollectionProperties(alterCollectionReq);
await client.alterCollectionProperties({
collection_name: "my_collection",
properties: {
"dynamicfield.enabled": true
}
});
err = client.AlterCollectionProperties(ctx, milvusclient.NewAlterCollectionPropertiesOption("my_collection").WithProperty(common.EnableDynamicSchemaKey, true))
if err != nil {
fmt.Println(err.Error())
// handle error
}
# restful
curl -X POST "YOUR_CLUSTER_ENDPOINT/v2/vectordb/collections/alter_properties" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <token>" \
-d '{
"collectionName": "my_collection",
"properties": {
"dynamicfield.enabled": "true"
}
}'
auto status = client->AlterCollectionProperties(milvus::AlterCollectionPropertiesRequest()
.WithCollectionName("my_collection")
.AddProperty("dynamicfield.enabled", "true"));
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}
例 6: allow_insert_auto_id を有効にする
allow_insert_auto_id プロパティを有効にすると、AutoID が有効なコレクションに対して、insert、upsert、バルクインポート時にユーザー指定の主キー値を受け入れられます。"true" に設定した場合、Zilliz Cloud はユーザー指定の主キー値が存在すればそれを使用し、存在しない場合は自動生成します。デフォルトは "false" です。
次の例は、allow_insert_auto_id を有効にする方法を示しています。
- Python
- Java
- NodeJS
- Go
- cURL
- C++
client.alter_collection_properties(
collection_name="my_collection",
properties={"allow_insert_auto_id": "true"}
)
# After enabling, inserts with a PK column will use that PK; otherwise Zilliz Cloud auto-generates.
AlterCollectionPropertiesReq alterCollectionReq = AlterCollectionPropertiesReq.builder()
.collectionName("my_collection")
.property("allow_insert_auto_id", "True")
.build();
client.alterCollectionProperties(alterCollectionReq);
await client.alterCollectionProperties({
collection_name: "my_collection",
properties: {
"allow_insert_auto_id": true
}
});
err = client.AlterCollectionProperties(ctx, milvusclient.NewAlterCollectionPropertiesOption("my_collection").WithProperty(common.AllowInsertAutoIDKey, true))
if err != nil {
fmt.Println(err.Error())
// handle error
}
# restful
curl -X POST "YOUR_CLUSTER_ENDPOINT/v2/vectordb/collections/alter_properties" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <token>" \
-d '{
"collectionName": "my_collection",
"properties": {
"allow_insert_auto_id": "true"
}
}'
auto status = client->AlterCollectionProperties(milvus::AlterCollectionPropertiesRequest()
.WithCollectionName("my_collection")
.AddProperty("allow_insert_auto_id", "true"));
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}
例 7: コレクションのタイムゾーンを設定する
timezone プロパティを使用して、コレクションのデフォルトタイムゾーンを設定できます。この設定により、データの挿入、クエリ、結果の表示など、コレクション内のすべての操作において、時間関連データがどのように解釈・表示されるかが決定されます。
timezone の値には、Asia/Shanghai、America/Chicago、UTC などの有効な IANA タイムゾーン識別子 を指定する必要があります。無効または非標準の値を指定すると、コレクションプロパティの変更時にエラーが発生します。
次の例は、コレクションのタイムゾーンを Asia/Shanghai: に設定する方法を示しています。
- Python
- Java
- NodeJS
- Go
- cURL
- C++
client.alter_collection_properties(
collection_name="my_collection",
properties={"timezone": "Asia/Shanghai"}
)
AlterCollectionPropertiesReq alterCollectionReq = AlterCollectionPropertiesReq.builder()
.collectionName("my_collection")
.property("timezone", "Asia/Shanghai")
.build();
client.alterCollectionProperties(alterCollectionReq);
// js
err = client.AlterCollectionProperties(ctx, milvusclient.NewAlterCollectionPropertiesOption("my_collection").WithProperty(common.CollectionDefaultTimezone, true))
if err != nil {
fmt.Println(err.Error())
// handle error
}
# restful
curl -X POST "YOUR_CLUSTER_ENDPOINT/v2/vectordb/collections/alter_properties" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <token>" \
-d '{
"collectionName": "my_collection",
"properties": {
"timezone": "Asia/Shanghai"
}
}'
auto status = client->AlterCollectionProperties(milvus::AlterCollectionPropertiesRequest()
.WithCollectionName("my_collection")
.AddProperty("timezone", "Asia/Shanghai"));
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}
コレクションプロパティを削除する
次のように、コレクションプロパティを削除してリセットすることもできます。
- Python
- Java
- NodeJS
- Go
- cURL
- C++
client.drop_collection_properties(
collection_name="my_collection",
property_keys=[
"collection.ttl.seconds"
]
)
client.dropCollectionProperties(DropCollectionPropertiesReq.builder()
.collectionName("my_collection")
.propertyKeys(Collections.singletonList("collection.ttl.seconds"))
.build());
client.dropCollectionProperties({
collection_name:"my_collection",
properties: ['collection.ttl.seconds'],
});
err = client.DropCollectionProperties(ctx, milvusclient.NewDropCollectionPropertiesOption("my_collection", common.CollectionTTLConfigKey))
if err != nil {
fmt.Println(err.Error())
// handle error
}
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/collections/drop_properties" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
--header "Request-Timeout: 10" \
-d '{
"collectionName": "my_collection",
"propertyKeys": [
"collection.ttl.seconds"
]
}'
auto status = client->DropCollectionProperties(milvus::DropCollectionPropertiesRequest()
.WithCollectionName("my_collection")
.AddPropertyKey(milvus::COLLECTION_TTL_SECONDS));
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}