Module: ElasticMapper::Index

Defined in:
lib/elastic_mapper/index.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

#delete_from_indexObject

Remove the document from the ElasticSearch index.



13
14
15
16
17
# 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

#indexObject

Index the ActiveModel in ElasticSearch.



6
7
8
9
10
# 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_hashHash

Generate a hash representation of the model.

Returns:

  • (Hash)

    hash representation of model.



22
23
24
25
26
27
28
# 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