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.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping.html)
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
- #indexes(name, options = {}, &block) ⇒ Object
-
#initialize(type, options = {}) ⇒ Mappings
constructor
A new instance of Mappings.
- #to_hash ⇒ Object
Constructor Details
#initialize(type, options = {}) ⇒ Mappings
Returns a new instance of Mappings.
39 40 41 42 43 |
# File 'lib/elasticsearch/model/indexing.rb', line 39 def initialize(type, ={}) @type = type = @mapping = {} end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
37 38 39 |
# File 'lib/elasticsearch/model/indexing.rb', line 37 def end |
Instance Method Details
#as_json(options = {}) ⇒ Object
74 75 76 |
# File 'lib/elasticsearch/model/indexing.rb', line 74 def as_json(={}) to_hash end |
#indexes(name, options = {}, &block) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/elasticsearch/model/indexing.rb', line 45 def indexes(name, = {}, &block) @mapping[name] = if block_given? @mapping[name][:type] ||= 'object' properties = @mapping[name][:type] == 'multi_field' ? :fields : :properties @mapping[name][properties] ||= {} previous = @mapping begin @mapping = @mapping[name][properties] self.instance_eval(&block) ensure @mapping = previous end end # Set the type to `string` by default # @mapping[name][:type] ||= 'string' self end |
#to_hash ⇒ Object
70 71 72 |
# File 'lib/elasticsearch/model/indexing.rb', line 70 def to_hash { @type.to_sym => .merge( properties: @mapping ) } end |