class Elastic::Commands::ImportIndexDocuments
Public Instance Methods
perform()
click to toggle source
# File lib/elastic/commands/import_index_documents.rb, line 5 def perform if collection.present? target.collect_from(collection, middleware_options) { |obj| queue obj } else target.collect_all(middleware_options) { |obj| queue obj } end flush end
Private Instance Methods
cache()
click to toggle source
# File lib/elastic/commands/import_index_documents.rb, line 16 def cache @cache ||= [] end
flush()
click to toggle source
# File lib/elastic/commands/import_index_documents.rb, line 25 def flush unless cache.empty? index.connector.bulk_index(cache) log_flush(cache.size) if verbose cache.clear end end
log_flush(_size)
click to toggle source
# File lib/elastic/commands/import_index_documents.rb, line 33 def log_flush(_size) @total ||= 0 @total += _size Elastic.logger.info "Imported #{@total} documents" end
middleware_options()
click to toggle source
# File lib/elastic/commands/import_index_documents.rb, line 47 def middleware_options index.definition.middleware_options end
queue(_object)
click to toggle source
# File lib/elastic/commands/import_index_documents.rb, line 20 def queue(_object) cache << render_for_es(_object) flush if cache.length >= batch_size end
render_for_es(_object)
click to toggle source
# File lib/elastic/commands/import_index_documents.rb, line 39 def render_for_es(_object) index.new(_object).as_elastic_document end
target()
click to toggle source
# File lib/elastic/commands/import_index_documents.rb, line 43 def target index.definition.target end