module EsClient::ActiveRecord::Glue::ClassMethods

Public Instance Methods

es_client_reindex(options={}) click to toggle source
# File lib/es_client/active_record/glue.rb, line 41
def es_client_reindex(options={})
  find_in_batches(options) do |batch|
    es_client.import(batch)
  end
end
es_client_reindex_with_progress(options={}) click to toggle source
# File lib/es_client/active_record/glue.rb, line 47
def es_client_reindex_with_progress(options={})
  find_in_batches_with_progress(options) do |batch|
    es_client.import(batch)
  end
end
find_in_batches_with_progress(options = {}) { |r| ... } click to toggle source
# File lib/es_client/active_record/glue.rb, line 53
def find_in_batches_with_progress(options = {})
  unless defined? ProgressBar
    warn "Install 'ruby-progressbar' gem to use '#{__method__}' method"
    return
  end
  options[:batch_size] ||= 1000
  total = (count / options[:batch_size].to_f).ceil
  title = options.delete(:name) || "#{name} batch_size:#{options[:batch_size]}"
  bar = ProgressBar.create(title: title, total: total, format: '%c of %C - %a %e |%b>>%i| %p%% %t')
  bar.progress_mark = '='
  find_in_batches(options) do |r|
    yield r
    bar.increment
  end
  bar.finish
end