使用Python重新索引Elasticsearch

首先

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

Elasticsearch 弹性搜索

确认

    • Bulk で入れる前にElasticSearchのインデクシングを高速化するを一読。とても参考になりました。

レプリカシャードを0に設定
コミットの頻度を変更
_allフィールドを無効化

创建一个新的指标

    前のindexで設定し忘れたシャードの数とか、マッピングとかを正しく入れる。
PUT 'XXX.XXX.XXX.XXX:9200/[new index]' -d '
index :
    number_of_shards : 3
    number_of_replicas : 0
'

批量 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")

推荐将索引的大小控制在大约10MB左右。请查看以下参考内容:考虑Elasticsearch索引性能的因素。

最后

    Bulk API簡単でよかったです。

请参考

    • Helpers

 

    • Elasticsearch + Pythonでバルクインサート(helpers.bulk)

 

    • ElasticSearchのインデクシングを高速化する

 

    Elasticsearchインデクシングパフォーマンスのための考慮事項
广告
将在 10 秒后关闭
bannerAds