Class: Fields
- Inherits:
-
Object
- Object
- Fields
- Defined in:
- lib/es_fields/fields.rb
Constant Summary collapse
- BASE_MAPPING =
{ "mappings": { "doc": { "properties": { } } } }
- TYPE_MAPPING =
{ string: 'text', long: 'long', date: 'date', keyword: 'keyword', double: 'double', boolean: 'boolean', ip: 'ip', }
- OPTIONS_MAPPING =
{ sortable: 'keyword', full_text_search: 'text', aggregation: 'keyword', filtering: 'keyword', }
Instance Method Summary collapse
- #field(name, type, options: []) ⇒ Object
-
#initialize ⇒ Fields
constructor
A new instance of Fields.
Constructor Details
#initialize ⇒ Fields
Returns a new instance of Fields.
29 30 31 |
# File 'lib/es_fields/fields.rb', line 29 def initialize @base_mapping = BASE_MAPPING.dup end |
Instance Method Details
#field(name, type, options: []) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/es_fields/fields.rb', line 33 def field(name, type, options: []) @base_mapping[:mappings][:doc][:properties].merge!( { name => { type: .empty? ? TYPE_MAPPING[type] : OPTIONS_MAPPING[.first] } } ) @base_mapping end |