Module: Elastics::Model::HelperMethods::ClassMethods
- Defined in:
- lib/elastics/model/helper_methods.rb
Instance Method Summary collapse
-
#bulk_elastics(params = {}, &block) ⇒ Object
Proxies #bulk method to elastics client with specified index & type.
-
#clear_elastics ⇒ Object
Deletes all records in type keeping its mapping using “Delete by query” API.
- #elastics_mapping ⇒ Object
- #elastics_params ⇒ Object
-
#index_batch_elastics(batch) ⇒ Object
Indexes given records using batch API.
-
#refresh_elastics ⇒ Object
Performs ‘_refresh` request on index.
-
#reindex_elastics(options = {}) ⇒ Object
Reindexes all records.
-
#request_elastics(params) ⇒ Object
Proxies #request method to elastics client with specified index & type.
-
#search_elastics(data = {}, options = {}) ⇒ Object
Performs ‘_search` request on type and instantiates result object.
Instance Method Details
#bulk_elastics(params = {}, &block) ⇒ Object
Proxies #bulk method to elastics client with specified index & type.
30 31 32 |
# File 'lib/elastics/model/helper_methods.rb', line 30 def bulk_elastics(params = {}, &block) elastics.bulk(elastics_params.merge!(params), &block) end |
#clear_elastics ⇒ Object
Deletes all records in type keeping its mapping using “Delete by query” API.
71 72 73 |
# File 'lib/elastics/model/helper_methods.rb', line 71 def clear_elastics request_elastics method: :delete, id: :_query, body: {query: {match_all: {}}} end |
#elastics_mapping ⇒ Object
75 76 77 |
# File 'lib/elastics/model/helper_methods.rb', line 75 def elastics_mapping request_elastics(id: :_mapping) end |
#elastics_params ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/elastics/model/helper_methods.rb', line 16 def elastics_params { index: elastics_index_name, type: elastics_type_name, model: self, } end |
#index_batch_elastics(batch) ⇒ Object
Indexes given records using batch API.
55 56 57 58 59 60 61 |
# File 'lib/elastics/model/helper_methods.rb', line 55 def index_batch_elastics(batch) bulk_elastics do |bulk| batch.each do |record| bulk.index record.id, record.to_elastics end end end |
#refresh_elastics ⇒ Object
Performs ‘_refresh` request on index.
50 51 52 |
# File 'lib/elastics/model/helper_methods.rb', line 50 def refresh_elastics request_elastics(method: :post, type: nil, id: :_refresh) end |
#reindex_elastics(options = {}) ⇒ Object
Reindexes all records. It requires #find_in_batches method to be defined.
64 65 66 67 68 |
# File 'lib/elastics/model/helper_methods.rb', line 64 def reindex_elastics( = {}) find_in_batches() do |batch| index_batch_elastics(batch) end end |
#request_elastics(params) ⇒ Object
Proxies #request method to elastics client with specified index & type.
25 26 27 |
# File 'lib/elastics/model/helper_methods.rb', line 25 def request_elastics(params) elastics.request(elastics_params.merge!(params)) end |
#search_elastics(data = {}, options = {}) ⇒ Object
Performs ‘_search` request on type and instantiates result object. Result::Search is a default result class. It can be overriden with :result_class option.
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/elastics/model/helper_methods.rb', line 37 def search_elastics(data = {}, = {}) request = { id: :_search, body: data, } if routing = [:routing] request[:query] = {routing: routing} end result_class = [:result_class] || Result::Search result_class.new request_elastics(request), end |