Class: Elasticsearch::Extensions::Documents::DirectIndexStore
- Inherits:
-
Object
- Object
- Elasticsearch::Extensions::Documents::DirectIndexStore
- Defined in:
- lib/elasticsearch/extensions/documents/direct_index_store.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#storage ⇒ Object
readonly
Returns the value of attribute storage.
Instance Method Summary collapse
- #bulk_index(documents) ⇒ Object
- #bulk_index_operation_hash(document) ⇒ Object
- #bulk_index_operations(documents) ⇒ Object
- #delete(payload) ⇒ Object
- #index(payload) ⇒ Object
-
#initialize(options = {}) ⇒ DirectIndexStore
constructor
A new instance of DirectIndexStore.
- #refresh ⇒ Object
- #reindex(options = {}, &block) ⇒ Object
- #search(payload) ⇒ Object
- #setup ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ DirectIndexStore
Returns a new instance of DirectIndexStore.
7 8 9 10 |
# File 'lib/elasticsearch/extensions/documents/direct_index_store.rb', line 7 def initialize( = {}) @client = .fetch(:client) { Documents.client } @storage = .fetch(:storage) { Storage.new } end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
5 6 7 |
# File 'lib/elasticsearch/extensions/documents/direct_index_store.rb', line 5 def client @client end |
#storage ⇒ Object (readonly)
Returns the value of attribute storage.
5 6 7 |
# File 'lib/elasticsearch/extensions/documents/direct_index_store.rb', line 5 def storage @storage end |
Instance Method Details
#bulk_index(documents) ⇒ Object
42 43 44 |
# 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) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# 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) ⇒ Object
46 47 48 |
# 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) ⇒ Object
16 17 18 |
# 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) ⇒ Object
12 13 14 |
# File 'lib/elasticsearch/extensions/documents/direct_index_store.rb', line 12 def index(payload) client.index payload.merge(index: Documents.index_name) end |
#refresh ⇒ Object
24 25 26 |
# File 'lib/elasticsearch/extensions/documents/direct_index_store.rb', line 24 def refresh client.indices.refresh index: Documents.index_name end |
#reindex(options = {}, &block) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/elasticsearch/extensions/documents/direct_index_store.rb', line 28 def reindex( = {}, &block) force_create = .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 |
#search(payload) ⇒ Object
20 21 22 |
# File 'lib/elasticsearch/extensions/documents/direct_index_store.rb', line 20 def search(payload) client.search payload.merge(index: Documents.index_name) end |
#setup ⇒ Object
37 38 39 40 |
# 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 |