使用Reindex將資料移轉至PolarSearch
Reindex API用於將自建Elasticsearch或OpenSearch叢集的資料移轉至PolarSearch。該API通過網路從遠端源叢集拉取索引資料到PolarSearch。
準備工作
開始操作前,請確認以下條件:
環境依賴:源Elasticsearch或OpenSearch叢集與PolarSearch節點部署在同一Virtual Private Cloud中。如果源叢集不在同一VPC中,請在操作前完成兩個環境之間的網路連通配置。
版本對應:PolarSearch版本與源叢集版本需相容。詳細相容說明,請參見版本選型指南。
步驟一:建立目標索引
執行Reindex任務前,在PolarSearch節點上建立與源索引相同Settings和Mappings的目標索引。
查詢源索引的Settings。
curl -XGET "http://<source_address>/<source_index>/_settings?pretty"查詢源索引的Mappings。
curl -XGET "http://<source_address>/<source_index>/_mapping?pretty"在PolarSearch節點上建立目標索引。將
<source_settings>和<source_mappings>替換為前述步驟擷取的實際Settings和Mappings。curl -X PUT "http://<dest_address>/<dest_index>?pretty" \ -u <dest_username>:<dest_password> \ -H 'Content-Type: application/json' \ -d'{ "settings": { <source_settings> }, "mappings": { <source_mappings> } }'
步驟二:配置Reindex白名單
要允許PolarSearch節點訪問遠端源叢集,需要將源叢集地址添加到Reindex白名單中。如果未配置白名單,Reindex任務會返回以下錯誤之一:
[address] not allowlisted in reindex.remote.allowlist[address] not allowlisted in reindex.remote.whitelist
目前暫不支援您手動設定白名單,如有需求,請提交工單聯絡我們為您處理。
白名單參數為靜態配置,修改後需要重啟PolarSearch節點才會生效。請在業務低峰期進行重啟,以減少對業務的影響。
步驟三:執行Reindex任務
在PolarSearch上執行以下命令啟動Reindex任務。資料將從遠端源叢集拉取到PolarSearch的目標索引。
curl -X POST "http://<dest_address>/_reindex?pretty" \ -u <dest_username>:<dest_password> \ -H 'Content-Type: application/json' \ -d'{ "source": { "remote": { "host": "http://<source_address>", "username": "<source_username>", "password": "<source_password>" }, "index": "<source_index>" // 需要Reindex遷移的源叢集索引名 }, "dest": { "index": "<dest_index>" // 遷移至PolarSearch的目標索引名 } }'參數說明
參數
說明
source_address源Elasticsearch或OpenSearch叢集的訪問地址,格式為
host:port。source_username訪問源叢集的使用者名稱。如果源叢集不需要身分識別驗證,可以省略
username和password欄位。source_password訪問源叢集的密碼。
source_index待遷移的源索引名稱。
dest_addressPolarSearch的訪問地址。
dest_username訪問PolarSearch的使用者名稱。
dest_password訪問PolarSearch的密碼。
dest_indexPolarSearch上的目標索引名稱。
Reindex任務完成後,通過比較源索引和目標索引的文檔數量來驗證遷移結果。
# 查詢源索引的文檔數量 curl -XGET "http://<source_address>/<source_index>/_count?pretty" # 查詢目標索引的文檔數量 curl -XGET "http://<dest_address>/<dest_index>/_count?pretty" \ -u <dest_username>:<dest_password>
常見問題
Q1:單次Reindex任務是否支援遷移多個索引?
不支援。Reindex API僅支援一對一的索引遷移。如需遷移多個索引,請為每個索引分別執行Reindex任務。同時,在Reindex遷移過程中不建議使用單次Reindex命令中使用多對一的方式進行資料移轉,容易引起資料或者欄位混淆。若需要遷移源端多個索引,可以使用多次Reindex命令一對一的方式進行遷移。例如:將
test_index1遷移至test_index_copy1,test_index2遷移至test_index_copy2。curl -X POST "http://<dest_address>/_reindex?pretty" \ -u <dest_username>:<dest_password> \ -H 'Content-Type: application/json' \ -d'{ "source": { "remote": { "host": "http://<source_address>", "username": "<source_username>", "password": "<source_password>" }, "index": "test_index1" // 需要Reindex遷移的源叢集索引名 }, "dest": { "index": "test_index_copy1" // 遷移至PolarSearch的目標索引名 } }' curl -X POST "http://<dest_address>/_reindex?pretty" \ -u <dest_username>:<dest_password> \ -H 'Content-Type: application/json' \ -d'{ "source": { "remote": { "host": "http://<source_address>", "username": "<source_username>", "password": "<source_password>" }, "index": "test_index2" // 需要Reindex遷移的源叢集索引名 }, "dest": { "index": "test_index_copy2" // 遷移至PolarSearch的目標索引名 } }'Q2:Reindex任務失敗並報illegal_argument_exception錯誤,如何處理?
該錯誤表示源索引中的欄位類型與目標索引的Mappings不相容。執行Reindex任務前,請確保目標索引的Mappings與源索引一致。
錯誤樣本:
"cause" : { "type" : "illegal_argument_exception", "reason" : "mapper [...] cannot be changed from type [float] to [long]" }Q3:如何為多個源叢集配置白名單?
如需從多個源叢集遷移資料,可以在提交工單聯絡我們的時候,將白名單參數中添加多個地址,用逗號分隔。例如:
reindex.remote.allowlist: "host1:9200, host2:9200"。
附錄:Reindex可用參數
請求樣本
curl -X POST "http://<dest_address>/_reindex?pretty&refresh=false&timeout=30s&wait_for_active_shards=1&wait_for_completion=false&requests_per_second=-1&require_alias=false&scroll=5m&slices=1&max_docs=100000"
-u <dest_username>:<dest_password>
-H 'Content-Type: application/json'
-d'
{
"source": {
"remote": {
"host": "http://<source_address>",
"username": "<source_username>",
"password": "<source_password>"
},
"index": "test_index" // 需要reindex遷移的索引名
},
"dest": {
"index": "test_index_copy" // 遷移至PolarSearch的索引名
}
}'參數說明
參數 | 類型 | 預設值 | 含義 |
| Boolean |
| 是否等待任務完成。
|
| Integer |
| 每秒處理的子請求數,用於限流。 |
| Time |
| 請求的逾時時間。您可以根據網路情況和任務複雜度適當延長此值(例如 |
| Boolean |
| 寫入後是否立即重新整理,使資料對搜尋可見。 |
| Integer / "auto" |
| 任務並行度,即將任務拆分為多少個子任務並存執行。設定為 說明 跨叢集Reindex時, |
| Integer | - | 本次任務最多處理的文檔數。預設處理所有匹配的文檔。您可以設定一個較小的值(如 |
| String |
| 執行任務前需啟用的分區數。在開始處理請求前,必須有指定數量的活躍分區可用。可選值為 |
| Time |
| 滾動查詢的上下文保持時間。在Reindex過程中,用於保持源索引的搜尋上下文(Scroll Context)有效。 |
| Boolean |
| 是否強制要求目標為別名。如果設定為 |