class Elasticsearch::Model::Indexing::Mappings
Wraps the [index mappings](www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html)
Constants
- TYPES_WITH_EMBEDDED_PROPERTIES
@private
Attributes
options[RW]
type[RW]
Public Class Methods
new(type = nil, options={})
click to toggle source
# File lib/elasticsearch/model/indexing.rb, line 59 def initialize(type = nil, options={}) @type = type @options = options @mapping = {} end
Public Instance Methods
as_json(options={})
click to toggle source
# File lib/elasticsearch/model/indexing.rb, line 97 def as_json(options={}) to_hash end
indexes(name, options={}, &block)
click to toggle source
# File lib/elasticsearch/model/indexing.rb, line 65 def indexes(name, options={}, &block) @mapping[name] = options if block_given? @mapping[name][:type] ||= 'object' properties = TYPES_WITH_EMBEDDED_PROPERTIES.include?(@mapping[name][:type].to_s) ? :properties : :fields @mapping[name][properties] ||= {} previous = @mapping begin @mapping = @mapping[name][properties] self.instance_eval(&block) ensure @mapping = previous end end # Set the type to `text` by default @mapping[name][:type] ||= 'text' self end
to_hash()
click to toggle source
# File lib/elasticsearch/model/indexing.rb, line 89 def to_hash if @type { @type.to_sym => @options.merge( properties: @mapping ) } else @options.merge( properties: @mapping ) end end