Module: EsClient::ActiveRecord::Glue::ClassMethods

Defined in:
lib/es_client/active_record/glue.rb

Instance Method Summary collapse

Instance Method Details

#es_client_reindex(options = {}) ⇒ Object



41
42
43
44
45
# 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 = {}) ⇒ Object



47
48
49
50
51
# 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 = {}) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# 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