コレクションの変更
コレクションの名前を変更したり、設定を変更したりできます。このページでは、コレクションを変更する方法について説明します。
コレクションの名前変更
以下のようにしてコレクションの名前を変更できます。
- Python
- Java
- NodeJS
- Go
- cURL
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" \
-d '{
"collectionName": "my_collection",
"newCollectionName": "my_new_collection"
}'
コレクションプロパティの設定
コレクション作成後、コレクションレベルのプロパティを変更できます。
このセクションに記載されているすべてのプロパティは、マネージドコレクションにのみ適用されます。
サポートされるプロパティ
プロパティ | 説明 |
|---|---|
| コレクションのデータを特定の期間後に削除する必要がある場合は、秒単位で Time-To-Live (TTL) を設定することを検討してください。TTL が期限切れになると、Zilliz Cloud はコレクションからすべてのエンティティを削除します。 削除は非同期で行われるため、削除が完了する前でも検索やクエリを実行可能です。 詳細については、コレクションレベルの TTL の設定をご覧ください。 |
| 各エンティティの絶対有効期限タイムスタンプ(エンティティレベルの TTL)を格納する 詳細については、エンティティレベルの TTL の設定をご覧ください。 |
| メモリマッピング (Mmap) により、ディスク上の大容量ファイルへの直接メモリアクセスが可能になり、Zilliz Cloud はインデックスとデータをメモリとハードドライブの両方に保存できます。このアプローチにより、アクセス頻度に基づいてデータ配置ポリシーを最適化し、検索パフォーマンスに影響を与えることなくコレクションのストレージ容量を拡張できます。 Zilliz Cloud は、クラスターに対してグローバル mmap 設定を実装しています。特定のフィールドまたはそのインデックスの設定を変更できます。 詳細については、「mmap の使用」をご覧ください。 |
| パーティションキー分離を有効にすると、Zilliz Cloud はパーティションキーの値に基づいてエンティティをグループ化し、これらの各グループに対して個別のインデックスを作成します。検索リクエストを受信すると、Zilliz Cloud はフィルタリング条件で指定されたパーティションキーの値に基づいてインデックスを特定し、検索範囲をそのインデックスに含まれるエンティティ内に制限します。これにより、検索中に無関係なエンティティのスキャンを回避し、検索パフォーマンスを大幅に向上させます。 詳細については、パーティションキー分離の使用をご覧ください。 |
| 有効化せずに作成されたコレクションに対して動的フィールドを有効にします。一度有効にすると、元のスキーマで定義されていないフィールドを持つエンティティを挿入できるようになります。詳細については、動的フィールドをご覧ください。 |
| コレクションに対して AutoID が有効になっている場合に、ユーザー提供の主キー値を受け入れるかどうかを指定します。
|
| 時間依存の操作、特に |
例 1: コレクションレベルの TTL の設定
以下のコードスニペットは、コレクションの TTL を設定する方法を示しています。
- Python
- Java
- NodeJS
- Go
- cURL
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" \
-d '{
"collectionName": "my_collection",
"properties": {
"collection.ttl.seconds": 60
}
}'
例 2: エンティティレベル TTL の設定Private Preview
以下のコードスニペットは、既存の TIMESTAMPTZ フィールド (expire_at) をエンティティレベル TTL の TTL フィールドとして指定します。コレクションには既にその名前の TIMESTAMPTZ フィールドが含まれている必要があり、collection.ttl.seconds は設定されていない必要があります — この 2 つの TTL モードは相互に排他的です。
エンティティレベル TTL の完全なワークフロー(スキーマ設定、挿入、クエリ、更新、削除)については、エンティティレベル TTL の設定 を参照してください。
- Python
- Java
- NodeJS
- Go
- cURL
from pymilvus import MilvusClient
client.alter_collection_properties(
collection_name="my_collection",
properties={"ttl_field": "expire_at"}
)
// java
// nodejs
// go
# restful
例 3: mmap を有効にする
以下のコードスニペットは、mmap を有効にする方法を示しています。
- Python
- Java
- NodeJS
- Go
- cURL
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"
}
}'
例 4: パーティションキーを有効にする
以下のコードスニペットは、パーティションキーを有効にする方法を示しています。
- Python
- Java
- NodeJS
- Go
- cURL
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"
}
}'
例 5: 動的フィールドを有効にする
以下のコードスニペットは、動的フィールドを有効にする方法を示しています。
- Python
- Java
- NodeJS
- Go
- cURL
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"
}
}'
例 6: allow_insert_auto_id の有効化
allow_insert_auto_id プロパティを有効にすると、AutoID が有効なコレクションに対して、挿入(insert)、更新挿入(upsert)、および批量インポート(bulk import)時にユーザーが指定した主キー値を受け入れることができます。この値が "true" に設定されている場合、Zilliz Cloud はユーザーが提供した主キー値が存在すればそれを使用し、存在しない場合は自動生成します。デフォルト値は "false" です。
以下の例では、allow_insert_auto_id を有効にする方法を示しています:
- Python
- Java
- NodeJS
- Go
- cURL
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"
}
}'
例 7: コレクションのタイムゾーンを設定する
timezone プロパティを使用して、コレクションのデフォルトタイムゾーンを設定できます。これにより、データ挿入、クエリ、結果表示を含むコレクション内のすべての操作において、時間関連データの解釈と表示方法が決定されます。
timezone の値は、有効な IANA タイムゾーン識別子 でなければなりません。例: Asia/Shanghai、America/Chicago、UTC など。無効または非標準の値を使用すると、コレクションプロパティの変更時にエラーが発生します。
以下の例は、コレクションのタイムゾーンを Asia/Shanghai に設定する方法を示しています:
- Python
- Java
- NodeJS
- Go
- cURL
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"
}
}'
コレクションプロパティの削除
以下のようにコレクションプロパティを削除することで、リセットすることもできます。
- Python
- Java
- NodeJS
- Go
- cURL
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" \
-d '{
"collectionName": "my_collection",
"propertyKeys": [
"collection.ttl.seconds"
]
}'