Module: Elasticsearch::Persistence::Repository::Find
- Included in:
- Class
- Defined in:
- lib/elasticsearch/persistence/repository/find.rb
Overview
Retrieves one or more domain objects from the repository
Instance Method Summary collapse
- #__find_many(ids, options = {}) ⇒ Object private
- #__find_one(id, options = {}) ⇒ Object private
-
#exists?(id, options = {}) ⇒ true, false
Return if object exists in the repository.
-
#find(*args) ⇒ Object, Array
Retrieve a single object or multiple objects from Elasticsearch by ID or IDs.
Instance Method Details
#__find_many(ids, options = {}) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
63 64 65 66 67 68 |
# File 'lib/elasticsearch/persistence/repository/find.rb', line 63 def __find_many(ids, ={}) type = document_type || (klass ? __get_type_from_class(klass) : '_all') documents = client.mget( { index: index_name, body: { ids: ids } }.merge() ) documents['docs'].map { |document| document['found'] ? deserialize(document) : nil } end |
#__find_one(id, options = {}) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
52 53 54 55 56 57 58 59 |
# File 'lib/elasticsearch/persistence/repository/find.rb', line 52 def __find_one(id, ={}) type = document_type || (klass ? __get_type_from_class(klass) : '_all') document = client.get( { index: index_name, id: id }.merge() ) deserialize(document) rescue Elasticsearch::Transport::Transport::Errors::NotFound => e raise DocumentNotFound, e., caller end |
#exists?(id, options = {}) ⇒ true, false
Return if object exists in the repository
45 46 47 48 |
# File 'lib/elasticsearch/persistence/repository/find.rb', line 45 def exists?(id, ={}) type = document_type || (klass ? __get_type_from_class(klass) : '_all') client.exists( { index: index_name, id: id }.merge() ) end |
#find(*args) ⇒ Object, Array
Retrieve a single object or multiple objects from Elasticsearch by ID or IDs
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/elasticsearch/persistence/repository/find.rb', line 24 def find(*args) = args.last.is_a?(Hash) ? args.pop : {} ids = args if args.size == 1 id = args.pop id.is_a?(Array) ? __find_many(id, ) : __find_one(id, ) else __find_many args, end end |