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
91 92 93 94 95 96 97 98 99 |
# File 'lib/elasticsearch/persistence/repository/store.rb', line 91 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, id: id }.merge()) end |
#save(document, options = {}) ⇒ Hash
Store the serialized object in Elasticsearch
37 38 39 40 41 42 43 44 |
# 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 } client.index(request.merge()) end |
#update(document_or_id, options = {}) ⇒ Hash
Update the serialized object in Elasticsearch with partial data or script
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/elasticsearch/persistence/repository/store.rb', line 63 def update(document_or_id, = {}) if document_or_id.is_a?(String) || document_or_id.is_a?(Integer) id = document_or_id body = else document = serialize(document_or_id) id = __extract_id_from_document(document) if [:script] body = else body = { doc: document }.merge() end end client.update(index: index_name, id: id, body: body) end |