Module: Estella::Helpers::ClassMethods
- Defined in:
- lib/estella/helpers.rb
Instance Method Summary collapse
- #batch_to_bulk(batch_of_ids) ⇒ Object
- #bulk_index(batch_of_ids) ⇒ Object
- #create_index! ⇒ Object
- #delete_index! ⇒ Object
- #es_delete_document(id) ⇒ Object
-
#estella_raw_search(params = {}) ⇒ Object
Searching.
-
#estella_search(params = {}) ⇒ Object
An array of database records mapped using an adapter.
-
#index_exists? ⇒ Boolean
True if the index exists.
- #recreate_index! ⇒ Object
- #refresh_index! ⇒ Object
- #reload_index! ⇒ Object
-
#search_index_name ⇒ Object
default index naming scheme is pluralized model_name.
Instance Method Details
#batch_to_bulk(batch_of_ids) ⇒ Object
60 61 62 |
# File 'lib/estella/helpers.rb', line 60 def batch_to_bulk(batch_of_ids) find(batch_of_ids).map(&:es_transform) end |
#bulk_index(batch_of_ids) ⇒ Object
64 65 66 67 |
# File 'lib/estella/helpers.rb', line 64 def bulk_index(batch_of_ids) create_index! unless index_exists? __elasticsearch__.client.bulk index: index_name, body: batch_to_bulk(batch_of_ids) end |
#create_index! ⇒ Object
78 79 80 81 82 83 |
# File 'lib/estella/helpers.rb', line 78 def create_index! __elasticsearch__.client.indices.create index: index_name, body: { settings: settings.to_hash, mappings: mappings.to_hash } end |
#delete_index! ⇒ Object
74 75 76 |
# File 'lib/estella/helpers.rb', line 74 def delete_index! __elasticsearch__.client.indices.delete index: index_name end |
#es_delete_document(id) ⇒ Object
100 101 102 |
# File 'lib/estella/helpers.rb', line 100 def es_delete_document(id) __elasticsearch__.client.delete id: id, index: index_name end |
#estella_raw_search(params = {}) ⇒ Object
Searching
43 44 45 |
# File 'lib/estella/helpers.rb', line 43 def estella_raw_search(params = {}) __elasticsearch__.search(estella_query(params)) end |
#estella_search(params = {}) ⇒ Object
Returns an array of database records mapped using an adapter.
48 49 50 51 |
# File 'lib/estella/helpers.rb', line 48 def estella_search(params = {}) rsp = estella_raw_search(params) params[:raw] ? rsp.response : rsp.records.to_a end |
#index_exists? ⇒ Boolean
Returns true if the index exists.
70 71 72 |
# File 'lib/estella/helpers.rb', line 70 def index_exists? __elasticsearch__.client.indices.exists index: index_name end |
#recreate_index! ⇒ Object
90 91 92 93 94 |
# File 'lib/estella/helpers.rb', line 90 def recreate_index! reload_index! import refresh_index! end |
#refresh_index! ⇒ Object
96 97 98 |
# File 'lib/estella/helpers.rb', line 96 def refresh_index! __elasticsearch__.refresh_index! end |
#reload_index! ⇒ Object
85 86 87 88 |
# File 'lib/estella/helpers.rb', line 85 def reload_index! delete_index! if index_exists? create_index! end |
#search_index_name ⇒ Object
default index naming scheme is pluralized model_name
56 57 58 |
# File 'lib/estella/helpers.rb', line 56 def search_index_name model_name.route_key end |