Module: ElasticMapper::Mapping::ClassMethods
- Defined in:
- lib/elastic_mapper/mapping.rb
Instance Method Summary collapse
-
#mapping(*args) ⇒ Object
Populates @_mapping with properties describing how the model should be indexed in ElasticSearch.
-
#mapping_hash ⇒ Hash
Generates a hash representation of @_mapping, compatible with ElasticSearch.
-
#mapping_name(mapping_name) ⇒ Object
Override the default name of the mapping.
-
#put_mapping ⇒ Object
Create the described mapping in ElasticSearch.
Instance Method Details
#mapping(*args) ⇒ Object
Populates @_mapping with properties describing how the model should be indexed in ElasticSearch. The last parameter is optionally a hash specifying index settings, e.g., analyzed, not_analyzed.
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/elastic_mapper/mapping.rb', line 27 def mapping(*args) = { :type => :string, :index => :analyzed }.update(args.) args.each do |arg| _mapping[mapping_key(arg)] = { field: arg, options: } end end |
#mapping_hash ⇒ Hash
Generates a hash representation of @_mapping, compatible with ElasticSearch.
85 86 87 88 89 90 91 |
# File 'lib/elastic_mapper/mapping.rb', line 85 def mapping_hash { @_mapping_name => { properties: @_mapping.inject({}) { |h, (k, v)| h[k] = v[:options]; h } } } end |
#mapping_name(mapping_name) ⇒ Object
Override the default name of the mapping.
77 78 79 |
# File 'lib/elastic_mapper/mapping.rb', line 77 def mapping_name(mapping_name) @_mapping_name = mapping_name.to_sym end |
#put_mapping ⇒ Object
Create the described mapping in ElasticSearch.
94 95 96 97 98 99 100 |
# File 'lib/elastic_mapper/mapping.rb', line 94 def put_mapping ElasticMapper.index .type(@_mapping_name) .put_mapping(mapping_hash) ElasticMapper.index.refresh end |