class Elasticsearch::Extensions::Documents::DirectIndexStore

Attributes

client[R]
storage[R]

Public Class Methods

new(options = {}) click to toggle source
# File lib/elasticsearch/extensions/documents/direct_index_store.rb, line 7
def initialize(options = {})
  @client  = options.fetch(:client)  { Documents.client }
  @storage = options.fetch(:storage) { Storage.new }
end

Public Instance Methods

bulk_index(documents) click to toggle source
# File lib/elasticsearch/extensions/documents/direct_index_store.rb, line 42
def bulk_index(documents)
  client.bulk body: bulk_index_operations(documents)
end
bulk_index_operation_hash(document) click to toggle source
# File lib/elasticsearch/extensions/documents/direct_index_store.rb, line 50
def bulk_index_operation_hash(document)
  {
    index: {
      _index: Documents.index_name,
      _type:  document.class.type,
      _id:    document.id,
      data:   document.as_hash,
    }
  }
end
bulk_index_operations(documents) click to toggle source
# File lib/elasticsearch/extensions/documents/direct_index_store.rb, line 46
def bulk_index_operations(documents)
  documents.collect { |document| bulk_index_operation_hash(document) }
end
delete(payload) click to toggle source
# File lib/elasticsearch/extensions/documents/direct_index_store.rb, line 16
def delete(payload)
  client.delete payload.merge(index: Documents.index_name)
end
index(payload) click to toggle source
# File lib/elasticsearch/extensions/documents/direct_index_store.rb, line 12
def index(payload)
  client.index payload.merge(index: Documents.index_name)
end
refresh() click to toggle source
# File lib/elasticsearch/extensions/documents/direct_index_store.rb, line 24
def refresh
  client.indices.refresh index: Documents.index_name
end
reindex(options = {}, &block) click to toggle source
# File lib/elasticsearch/extensions/documents/direct_index_store.rb, line 28
def reindex(options = {}, &block)
  force_create = options.fetch(:force_create) { false }

  storage.drop_index(Documents.index_name) if force_create
  storage.create_index(Documents.index_name)

  block.call(self) if block_given?
end
setup() click to toggle source
# File lib/elasticsearch/extensions/documents/direct_index_store.rb, line 37
def setup
  storage.drop_index(Documents.index_name)
  storage.create_index(Documents.index_name)
end