Module: Elasticsearch::Persistence::Repository::Store
- Included in:
- Elasticsearch::Persistence::Repository
- Defined in:
- lib/elasticsearch/persistence/repository/store.rb
Overview
Save and delete documents in Elasticsearch
Instance Method Summary collapse
-
#delete(document_or_id, options = {}) ⇒ Hash
Remove the serialized object or document with specified ID from Elasticsearch.
-
#save(document, options = {}) ⇒ Hash
Store the serialized object in Elasticsearch.
-
#update(document_or_id, options = {}) ⇒ Hash
Update the serialized object in Elasticsearch with partial data or script.
Instance Method Details
#delete(document_or_id, options = {}) ⇒ Hash
Remove the serialized object or document with specified ID from Elasticsearch
94 95 96 97 98 99 100 101 102 |
# File 'lib/elasticsearch/persistence/repository/store.rb', line 94 def delete(document_or_id, = {}) if document_or_id.is_a?(String) || document_or_id.is_a?(Integer) id = document_or_id else serialized = serialize(document_or_id) id = __get_id_from_document(serialized) end client.delete({ index: index_name, type: document_type, id: id }.merge()) end |
#save(document, options = {}) ⇒ Hash
Store the serialized object in Elasticsearch
37 38 39 40 41 42 43 44 45 |
# File 'lib/elasticsearch/persistence/repository/store.rb', line 37 def save(document, ={}) serialized = serialize(document) id = __get_id_from_document(serialized) request = { index: index_name, id: id, body: serialized } request[:type] = document_type if document_type client.index(request.merge()) end |
#update(document_or_id, options = {}) ⇒ Hash
Update the serialized object in Elasticsearch with partial data or script
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/elasticsearch/persistence/repository/store.rb', line 64 def update(document_or_id, = {}) if document_or_id.is_a?(String) || document_or_id.is_a?(Integer) id = document_or_id body = type = document_type else document = serialize(document_or_id) id = __extract_id_from_document(document) if [:script] body = else body = { doc: document }.merge() end type = document.delete(:type) || document_type end client.update(index: index_name, id: id, type: type, body: body) end |