はじめに
- あるindexを作りなおしたい(=reindex)ときにBulk APIを使ってインサートするのが推奨されている。とくに本番環境とかではないので、Aliasうんたらっていうのは不要でしたので、Python APIで実施したときの調べたメモ。
Elasticsearch
確認
- Bulk で入れる前にElasticSearchのインデクシングを高速化するを一読。とても参考になりました。
- レプリカシャードを0に設定
- コミットの頻度を変更
- _allフィールドを無効化
新しいIndexを作成
- 前のindexで設定し忘れたシャードの数とか、マッピングとかを正しく入れる。
PUT 'XXX.XXX.XXX.XXX:9200/[new index]' -d '
index :
number_of_shards : 3
number_of_replicas : 0
'
Bulk API (Pythonで)
Helpersのドキュメントを読む。と以下の感じでできそう。
from elasticsearch import Elasticsearch
from elasticsearch import helpers
es = Elasticsearch(host="XXX.XXX.XXX.XXX", port=9200)
helpers.reindex(es, source_index = "old-index", target_index = "new-index")
indexのサイズは10MBくらいずつ入れるのが推奨。下記参考より。
参考:Elasticsearchインデクシングパフォーマンスのための考慮事項
おわりに
- Bulk API簡単でよかったです。