LoginSignup
9

More than 5 years have passed since last update.

PythonでElasticsearchのReindex

Last updated at Posted at 2016-02-06

はじめに

  • あるindexを作りなおしたい(=reindex)ときにBulk APIを使ってインサートするのが推奨されている。とくに本番環境とかではないので、Aliasうんたらっていうのは不要でしたので、Python APIで実施したときの調べたメモ。

Elasticsearch

確認

新しい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簡単でよかったです。

参考

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9