Module: Estella::Helpers::ClassMethods

Defined in:
lib/estella/helpers.rb

Instance Method Summary collapse

Instance Method Details

#batch_to_bulk(batch_of_ids) ⇒ Object



58
59
60
# File 'lib/estella/helpers.rb', line 58

def batch_to_bulk(batch_of_ids)
  find(batch_of_ids).map(&:es_transform)
end

#bulk_index(batch_of_ids) ⇒ Object



62
63
64
65
# File 'lib/estella/helpers.rb', line 62

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

#create_index!Object



76
77
78
# File 'lib/estella/helpers.rb', line 76

def create_index!
  __elasticsearch__.client.indices.create index: index_name, body: { settings: settings.to_hash, mappings: mappings.to_hash }
end

#delete_index!Object



72
73
74
# File 'lib/estella/helpers.rb', line 72

def delete_index!
  __elasticsearch__.client.indices.delete index: index_name
end

#es_delete_document(id) ⇒ Object



95
96
97
# File 'lib/estella/helpers.rb', line 95

def es_delete_document(id)
  __elasticsearch__.client.delete type: document_type, id: id, index: index_name
end

#estella_raw_search(params = {}) ⇒ Object

Searching



41
42
43
# File 'lib/estella/helpers.rb', line 41

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.

Returns:

  • an array of database records mapped using an adapter



46
47
48
49
# File 'lib/estella/helpers.rb', line 46

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.

Returns:

  • (Boolean)

    true if the index exists



68
69
70
# File 'lib/estella/helpers.rb', line 68

def index_exists?
  __elasticsearch__.client.indices.exists index: index_name
end

#recreate_index!Object



85
86
87
88
89
# File 'lib/estella/helpers.rb', line 85

def recreate_index!
  reload_index!
  import
  refresh_index!
end

#refresh_index!Object



91
92
93
# File 'lib/estella/helpers.rb', line 91

def refresh_index!
  __elasticsearch__.refresh_index!
end

#reload_index!Object



80
81
82
83
# File 'lib/estella/helpers.rb', line 80

def reload_index!
  delete_index! if index_exists?
  create_index!
end

#search_index_nameObject

default index naming scheme is pluralized model_name



54
55
56
# File 'lib/estella/helpers.rb', line 54

def search_index_name
  model_name.route_key
end