Skip to content

Instantly share code, notes, and snippets.

@awwaiid
Created December 3, 2014 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save awwaiid/ad7b0eb0ffb2eafa4e39 to your computer and use it in GitHub Desktop.
Save awwaiid/ad7b0eb0ffb2eafa4e39 to your computer and use it in GitHub Desktop.
index a given array of records
# app/searchers/elasticsearch/bulk_indexable.rb
# This was my sketch of an idea for a way to index a specific given set of records
# "records" here is an array of units, which it batches with #each_slice
def index_records(records, new_index=nil)
Rails.logger.info("[ElasticSearch] Indexing given records")
records.each_slice(BULK_OPERATION_LIMIT) do |record_batch|
batch_index(record_batch, new_index)
end
client.indices.optimize index: (new_index || index_name)
set_latest_reindex_at end_at
offset
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment