module Elastics::Model::HelperMethods::ClassMethods

Public Instance Methods

bulk_elastics(params = {}, &block) click to toggle source

Proxies bulk method to elastics client with specified index & type.

# File lib/elastics/model/helper_methods.rb, line 30
def bulk_elastics(params = {}, &block)
  elastics.bulk(elastics_params.merge!(params), &block)
end
clear_elastics() click to toggle source

Deletes all records in type keeping its mapping using “Delete by query” API.

# 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() click to toggle source
# File lib/elastics/model/helper_methods.rb, line 75
def elastics_mapping
  request_elastics(id: :_mapping)
end
elastics_params() click to toggle source
# 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) click to toggle source

Indexes given records using batch API.

# 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() click to toggle source

Performs `_refresh` request on index.

# File lib/elastics/model/helper_methods.rb, line 50
def refresh_elastics
  request_elastics(method: :post, type: nil, id: :_refresh)
end
reindex_elastics(options = {}) click to toggle source

Reindexes all records. It requires find_in_batches method to be defined.

# File lib/elastics/model/helper_methods.rb, line 64
def reindex_elastics(options = {})
  find_in_batches(options) do |batch|
    index_batch_elastics(batch)
  end
end
request_elastics(params) click to toggle source

Proxies request method to elastics client with specified index & type.

# File lib/elastics/model/helper_methods.rb, line 25
def request_elastics(params)
  elastics.request(elastics_params.merge!(params))
end
search_elastics(data = {}, options = {}) click to toggle source

Performs `_search` request on type and instantiates result object. Result::Search is a default result class. It can be overriden with :result_class option.

# File lib/elastics/model/helper_methods.rb, line 37
def search_elastics(data = {}, options = {})
  request = {
    id:     :_search,
    body:   data,
  }
  if routing = options[:routing]
    request[:query] = {routing: routing}
  end
  result_class = options[:result_class] || Result::Search
  result_class.new request_elastics(request), options
end