從 Elasticsearch
本指南提供了從 Elasticsearch 遷移資料到 Milvus 2.x 的全面、逐步的過程。按照本指南,您將能夠有效地傳輸資料,並利用 Milvus 2.x 的先進功能和改進的性能。
先決條件
- 軟體版本:
- 源 Elasticsearch:7.x 或 8.x
- 目標 Milvus:2.x
- 如需安裝細節,請參閱安裝 Elasticsearch和安裝 Milvus。
- 所需的工具:
- Milvus-migration工具。安裝細節請參閱安裝遷移工具。
- 支援遷移的資料類型:要從來源 Elasticsearch 索引遷移的欄位屬於下列類型 -dense_vector、關鍵字、文字、長、整數、雙數、浮點 數、布林、物件。此處未列出的資料類型目前不支援遷移。有關 Milvus 集合與 Elasticsearch 索引之間資料對應的詳細資訊,請參閱欄位對應參考。
- Elasticsearch 索引要求:
- 來源 Elasticsearch 索引必須包含
dense_vector
類型的向量欄位。沒有向量欄位就無法開始遷移。
- 來源 Elasticsearch 索引必須包含
設定轉移檔案
將範例的轉移設定檔儲存為migration.yaml
,然後根據您的實際情況修改設定。您可以將配置檔案放在任何本機目錄中。
dumper: # configs for the migration job.
worker:
workMode: "elasticsearch" # operational mode of the migration job.
reader:
bufferSize: 2500 # buffer size to read from Elasticsearch in each batch. A value ranging from 2000 to 4000 is recommended.
meta: # meta configs for the source Elasticsearch index and target Milvus 2.x collection.
mode: "config" # specifies the source for meta configs. currently, onlly `config` is supported.
version: "8.9.1"
index: "qatest_index" # identifies the Elasticsearch index to migrate data from.
fields: # fields within the Elasticsearch index to be migrated.
- name: "my_vector" # name of the Elasticsearch field.
type: "dense_vector" # data type of the Elasticsearch field.
dims: 128 # dimension of the vector field. required only when `type` is `dense_vector`.
- name: "id"
pk: true # specifies if the field serves as a primary key.
type: "long"
- name: "num"
type: "integer"
- name: "double1"
type: "double"
- name: "text1"
maxLen: 1000 # max. length of data fields. required only for `keyword` and `text` data types.
type: "text"
- name: "bl1"
type: "boolean"
- name: "float1"
type: "float"
milvus: # configs specific to creating the collection in Milvus 2.x
collection: "Collection_01" # name of the Milvus collection. defaults to the Elasticsearch index name if not specified.
closeDynamicField: false # specifies whether to disable the dynamic field in the collection. defaults to `false`.
shardNum: 2 # number of shards to be created in the collection.
consistencyLevel: Strong # consistency level for Milvus collection.
source: # connection configs for the source Elasticsearch server
es:
urls:
- "http://10.15.1.***:9200" # address of the source Elasticsearch server.
username: "" # username for the Elasticsearch server.
password: "" # password for the Elasticsearch server.
target:
mode: "remote" # storage location for dumped files. valid values: `remote` and `local`.
remote: # configs for remote storage
outputDir: "migration/milvus/test" # output directory path in the cloud storage bucket.
cloud: "aws" # cloud storage service provider. Examples: `aws`, `gcp`, `azure`, etc.
region: "us-west-2" # region of the cloud storage; can be any value if using local Minio.
bucket: "zilliz-aws-us-****-*-********" # bucket name for storing data; must align with configs in milvus.yaml for Milvus 2.x.
useIAM: true # whether to use an IAM Role for connection.
checkBucket: false # checks if the specified bucket exists in the storage.
milvus2x: # connection configs for the target Milvus 2.x server
endpoint: "http://10.102.*.**:19530" # address of the target Milvus server.
username: "****" # username for the Milvus 2.x server.
password: "******" # password for the Milvus 2.x server.
下表描述了示例配置文件中的參數。如需完整的配置清單,請參考Milvus Migration:Elasticsearch 到 Milvus 2.x.
dumper
參數 說明 dumper.worker.workMode
遷移工作的運作模式。從 Elasticsearch 索引遷移時設定為 elasticsearch
。dumper.worker.reader.bufferSize
每批從 Elasticsearch 讀取的緩衝區大小。單位:KB:KB。 meta
參數 說明 meta.mode
指定元組態的來源。目前僅支援 config
。meta.index
指定要遷移資料的 Elasticsearch 索引。 meta.fields
要遷移的 Elasticsearch 索引中的欄位。 meta.fields.name
Elasticsearch 欄位的名稱。 meta.fields.maxLen
欄位的最大長度。此參數僅在 meta.fields.type
為keyword
或text
時才需要。meta.fields.pk
指定欄位是否作為主索引鍵。 meta.fields.type
Elasticsearch 欄位的資料類型。目前,Elasticsearch 支援下列資料類型:dense_vector、keyword、text、long、integer、double、float、boolean、object。 meta.fields.dims
向量欄位的尺寸。這個參數只有在 meta.fields.type
是dense_vector
時才需要。meta.milvus
在 Milvus 2.x 中建立集合的特定組態。 meta.milvus.collection
Milvus 集合的名稱。如果未指定,則預設為 Elasticsearch 索引名稱。 meta.milvus.closeDynamicField
指定是否停用資料集中的動態欄位。預設為 false
。如需關於動態欄位的詳細資訊,請參閱啟用動態欄位。meta.milvus.shardNum
要在集合中建立的分塊數量。有關分片的詳細資訊,請參閱名詞。 meta.milvus.consistencyLevel
在 Milvus 中集合的一致性層級。如需更多資訊,請參閱一致性。 source
參數 說明 source.es
來源 Elasticsearch 伺服器的連線設定。 source.es.urls
來源 Elasticsearch 伺服器的位址。 source.es.username
Elasticsearch 伺服器的使用者名稱。 source.es.password
Elasticsearch 伺服器的密碼。 target
參數 說明 target.mode
轉儲檔案的儲存位置。有效值:
-local
: 在本機磁碟上儲存轉儲檔案。
-remote
: 在物件儲存空間上儲存轉儲檔案。target.remote.outputDir
雲端儲存桶中的輸出目錄路徑。 target.remote.cloud
雲端儲存服務提供商。範例值: aws
,gcp
,azure
。target.remote.region
雲端儲存區域。如果使用本機 MinIO,則可以是任何值。 target.remote.bucket
儲存資料的 Bucket 名稱。該值必須與 Milvus 2.x 中的配置相同。如需詳細資訊,請參閱系統配置。 target.remote.useIAM
是否使用 IAM 角色進行連接。 target.remote.checkBucket
是否檢查指定的資料桶是否存在於物件儲存空間。 target.milvus2x
目標 Milvus 2.x 伺服器的連線設定。 target.milvus2x.endpoint
目標 Milvus 伺服器的位址。 target.milvus2x.username
Milvus 2.x 伺服器的使用者名稱。如果您的 Milvus 伺服器啟用使用者驗證,則必須使用此參數。如需詳細資訊,請參閱啟用驗證。 target.milvus2x.password
Milvus 2.x 伺服器的密碼。如果您的 Milvus 伺服器啟用使用者驗證,則必須使用此參數。如需更多資訊,請參閱啟用驗證。
啟動遷移工作
使用以下命令啟動遷移工作。將{YourConfigFilePath}
改為配置檔案migration.yaml
所在的本機目錄。
./milvus-migration start --config=/{YourConfigFilePath}/migration.yaml
以下是成功的遷移日誌輸出範例:
[task/load_base_task.go:94] ["[LoadTasker] Dec Task Processing-------------->"] [Count=0] [fileName=testfiles/output/zwh/migration/test_mul_field4/data_1_1.json] [taskId=442665677354739304]
[task/load_base_task.go:76] ["[LoadTasker] Progress Task --------------->"] [fileName=testfiles/output/zwh/migration/test_mul_field4/data_1_1.json] [taskId=442665677354739304]
[dbclient/cus_field_milvus2x.go:86] ["[Milvus2x] begin to ShowCollectionRows"]
[loader/cus_milvus2x_loader.go:66] ["[Loader] Static: "] [collection=test_mul_field4_rename1] [beforeCount=50000] [afterCount=100000] [increase=50000]
[loader/cus_milvus2x_loader.go:66] ["[Loader] Static Total"] ["Total Collections"=1] [beforeTotalCount=50000] [afterTotalCount=100000] [totalIncrease=50000]
[migration/es_starter.go:25] ["[Starter] migration ES to Milvus finish!!!"] [Cost=80.009174459]
[starter/starter.go:106] ["[Starter] Migration Success!"] [Cost=80.00928425]
[cleaner/remote_cleaner.go:27] ["[Remote Cleaner] Begin to clean files"] [bucket=a-bucket] [rootPath=testfiles/output/zwh/migration]
[cmd/start.go:32] ["[Cleaner] clean file success!"]
驗證結果
執行遷移工作後,您可以進行 API 呼叫或使用 Attu 檢視已遷移實體的數量。如需詳細資訊,請參閱Attu和get_collection_stats()。
欄位對應參考
檢視下表以瞭解 Elasticsearch 索引中的欄位類型如何對應至 Milvus 集合中的欄位類型。
有關 Milvus 支援的資料類型的詳細資訊,請參閱支援的資料類型。
Elasticsearch 欄位類型 | Milvus 欄位類型 | 說明 |
---|---|---|
密集向量 | 浮動向量 | 向量尺寸在遷移時保持不變。 |
關鍵字 | VarChar | 設定最大長度 (1 到 65,535).超過限制的字串會觸發遷移錯誤。 |
文字 | VarChar | 設定最大長度(1 至 65,535)。超過限制的字串可能會觸發移轉錯誤。 |
長 | Int64 | - |
整數 | Int32 | - |
雙 | 雙倍 | - |
浮點數 | 浮動 | - |
布林 | 整數 | - |
物件 | JSON | - |