lib/estella/helpers.rb in estella-0.2.1 vs lib/estella/helpers.rb in estella-0.2.2
- old
+ new
@@ -26,27 +26,27 @@
ensure
self.es_indexing = nil
end
def es_delete
- es_delete_document id
+ self.class.es_delete_document(id)
end
def es_transform
{ index: { _id: id.to_s, data: as_indexed_json } }
end
module ClassMethods
## Searching
- def stella_raw_search(params = {})
+ def estella_raw_search(params = {})
__elasticsearch__.search(estella_query(params))
end
# @return an array of database records mapped using an adapter
def estella_search(params = {})
- rsp = stella_raw_search(params)
+ rsp = estella_raw_search(params)
params[:raw] ? rsp.response : rsp.records.to_a
end
## Indexing
@@ -58,33 +58,39 @@
def batch_to_bulk(batch_of_ids)
find(batch_of_ids).map(&:es_transform)
end
def bulk_index(batch_of_ids)
+ create_index! unless index_exists?
__elasticsearch__.client.bulk index: index_name, type: model_name.element, body: batch_to_bulk(batch_of_ids)
end
+ # @return true if the index exists
def index_exists?
__elasticsearch__.client.indices.exists index: index_name
end
- def reload_index!
- __elasticsearch__.client.indices.delete index: index_name if index_exists?
+ def delete_index!
+ __elasticsearch__.client.indices.delete index: index_name
+ end
+
+ def create_index!
__elasticsearch__.client.indices.create index: index_name, body: { settings: settings.to_hash, mappings: mappings.to_hash }
end
+ def reload_index!
+ delete_index! if index_exists?
+ create_index!
+ end
+
def recreate_index!
reload_index!
import
refresh_index!
end
def refresh_index!
__elasticsearch__.refresh_index!
- end
-
- def set_index_alias!(name)
- __elasticsearch__.client.indices.put_alias index: index_name, name: name
end
def es_delete_document(id)
__elasticsearch__.client.delete type: document_type, id: id, index: index_name
end