Class: Elasticsearch::Model::Indexing::Mappings
- Inherits:
-
Object
- Object
- Elasticsearch::Model::Indexing::Mappings
- Defined in:
- lib/elasticsearch/model/indexing.rb
Overview
Wraps the [index mappings](www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html)
Constant Summary collapse
- TYPES_WITH_EMBEDDED_PROPERTIES =
%w(object nested)
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
- #indexes(name, options = {}, &block) ⇒ Object
-
#initialize(type = nil, options = {}) ⇒ Mappings
constructor
A new instance of Mappings.
- #to_hash ⇒ Object
Constructor Details
#initialize(type = nil, options = {}) ⇒ Mappings
Returns a new instance of Mappings.
59 60 61 62 63 |
# File 'lib/elasticsearch/model/indexing.rb', line 59 def initialize(type = nil, ={}) @type = type @options = @mapping = {} end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
54 55 56 |
# File 'lib/elasticsearch/model/indexing.rb', line 54 def @options end |
#type ⇒ Object
Returns the value of attribute type.
54 55 56 |
# File 'lib/elasticsearch/model/indexing.rb', line 54 def type @type end |
Instance Method Details
#as_json(options = {}) ⇒ Object
97 98 99 |
# File 'lib/elasticsearch/model/indexing.rb', line 97 def as_json(={}) to_hash end |
#indexes(name, options = {}, &block) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/elasticsearch/model/indexing.rb', line 65 def indexes(name, ={}, &block) @mapping[name] = 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 ⇒ Object
89 90 91 92 93 94 95 |
# 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 |