module ElasticMapper::Index

Indexes the ActiveModel instance for search, based on the mapping outlined using ElasticMapper::Mapping.

Public Instance Methods

delete_from_index() click to toggle source

Remove the document from the ElasticSearch index.

# File lib/elastic_mapper/index.rb, line 13
def delete_from_index
  mapping_name = self.class.instance_variable_get(:@_mapping_name)

  ElasticMapper.index.type(mapping_name).delete(self.id)
end
index() click to toggle source

Index the ActiveModel in ElasticSearch.

# File lib/elastic_mapper/index.rb, line 6
def index
  mapping_name = self.class.instance_variable_get(:@_mapping_name)

  ElasticMapper.index.type(mapping_name).put(self.id, index_hash)
end
index_hash() click to toggle source

Generate a hash representation of the model.

@return [Hash] hash representation of model.

# File lib/elastic_mapper/index.rb, line 22
def index_hash
  mapping = self.class.instance_variable_get(:@_mapping)
  mapping.inject({}) do |h, (k, v)|
    h[k] = self.send(v[:field])
    h
  end
end