Method: Chewy::Type::Mapping::ClassMethods#template

Defined in:
lib/chewy/type/mapping.rb

#template(*args) ⇒ Object Also known as: dynamic_template

Defines dynamic template in mapping root objects

Name for each template is generated with the following rule: template_#!{dynamic_templates.size + 1}.

Examples:

class CarsIndex < Chewy::Index
  define_type Car do
    template 'model.*', type: 'text', analyzer: 'special'
    field 'model', type: 'object' # here we can put { de: 'Der Mercedes', en: 'Mercedes' }
                                  # and template will be applyed to this field
  end
end

Templates

template 'tit*', mapping_hash
template 'title.*', mapping_hash # dot in template causes "path_match" using
template /tit.+/, mapping_hash # using "match_pattern": "regexp"
template /title\..+/, mapping_hash # "\." - escaped dot causes "path_match" using
template /tit.+/, type: 'text', mapping_hash # "match_mapping_type" as the optionsl second argument
template template42: {match: 'hello*', mapping: {type: 'object'}} # or even pass a template as is


178
179
180
# File 'lib/chewy/type/mapping.rb', line 178

def template(*args)
  root.dynamic_template(*args)
end