Module: Elasticsearch::Model::Extensions::BatchUpdating::Association::Extension

Defined in:
lib/elasticsearch/model/extensions/batch_updating.rb

Instance Method Summary collapse

Instance Method Details

#update_index_for_ids_from(from, to:, index: nil, type: nil, batch_size: DEFAULT_BATCH_SIZE) ⇒ Object



121
122
123
124
125
126
127
# File 'lib/elasticsearch/model/extensions/batch_updating.rb', line 121

def update_index_for_ids_from(from, to:, index: nil, type: nil, batch_size: DEFAULT_BATCH_SIZE)
  record_id = arel_table[:id]

  conditions = record_id.gteq(from).and(record_id.lteq(to))

  update_index_in_batches(batch_size: batch_size, index: index, type: type, conditions: conditions)
end

#update_index_for_ids_in_range(range, index: nil, type: nil, batch_size: DEFAULT_BATCH_SIZE) ⇒ Object



129
130
131
# File 'lib/elasticsearch/model/extensions/batch_updating.rb', line 129

def update_index_for_ids_in_range(range, index: nil, type: nil, batch_size: DEFAULT_BATCH_SIZE)
  update_index_for_ids_from(range.first, to: range.last, type: type, index: index, batch_size: batch_size)
end

#update_index_in_batches(batch_size: DEFAULT_BATCH_SIZE, conditions: nil, index: nil, type: nil) ⇒ Object



133
134
135
136
137
# File 'lib/elasticsearch/model/extensions/batch_updating.rb', line 133

def update_index_in_batches(batch_size: DEFAULT_BATCH_SIZE, conditions:nil, index: nil, type: nil)
  find_in_batches(batch_size: batch_size, conditions: conditions) do |records|
    klass.update_index_in_batch(records, index: index, type: type)
  end
end

#update_index_in_chunks(num, index: index) ⇒ Object



111
112
113
114
115
116
117
118
119
# File 'lib/elasticsearch/model/extensions/batch_updating.rb', line 111

def update_index_in_chunks(num, index: index)
  klass.split_ids_into(num).map do |r|
    if block_given?
      yield -> { update_index_for_ids_in_range(r, index: index) }
    else
      update_index_for_ids_in_range(r, index: index)
    end
  end
end