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

#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.



15
16
17
18
19
20
21
# File 'lib/elastic_mapper/index.rb', line 15

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