私はタイヤの宝石 (Elsaticsearch クライアントとして使用) ライブラリ、特に reindex メソッドを使用しています。ruby スクリプトへのリンクは次のとおりです: https://github.com/karmi/tire/blob/master/lib/tire/index.rb
これがタイヤジェムの reindex メソッドです。
def reindex(name, options={}, &block)
new_index = Index.new(name)
new_index.create(options) unless new_index.exists?
transform = options.delete(:transform)
Search::Scan.new(self.name, &block).each do |results|
documents = results.map do |document|
document = document.to_hash.except(:type, :_index, :_explanation, :_score, :_version, :highlight, :sort)
document = transform.call(document) if transform
document
end
new_index.bulk_store documents
end
end
再インデックスを行うために、スクロールとスキャンの概念全体を取得します。しかし、私が理解できないのは、上記の方法の変換オプションです。
これは何をしますか:
transform = options.delete(:transform)
この:
document = transform.call(document) if transform
成し遂げる?
:transform オプションの使用方法に関する例または使用例を誰か提供できますか?