Method: Chewy::Index::Mapping::ClassMethods#template

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

#template(*args, **options) ⇒ 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
  index_scope Car
  template 'model.*', type: 'text', analyzer: 'special'
  field 'model', type: 'object' # here we can put { de: 'Der Mercedes', en: 'Mercedes' }
                                # and template will be applied to this field
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 an optional second argument
template template42: {match: 'hello*', mapping: {type: 'object'}} # or even pass a template as is


173
174
175
# File 'lib/chewy/index/mapping.rb', line 173

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