How it works...

The root object (document) controls the behavior of its fields and all its children object fields. In document mapping, we can define the following:

  • date_detection: This enables the extraction of a date from a string (true default).
  • dynamic_date_formats: This is a list of valid date formats. This is used if date_detection is active.
  • numeric_detection: This enables you to convert strings into numbers, if possible (false default).
  • dynamic_templates: This is a list of templates that's used to change the explicit mapping inference. If one of these templates is matched, the rules defined in it are used to build the final mapping.

A dynamic template is composed of two parts: the matcher and the mapping one.

To match a field to activate the template, several types of matchers are available such as:

  • match: This allows you to define a match on the field name. The expression is a standard GLOB pattern (http://en.wikipedia.org/wiki/Glob_(programming)).
  • unmatch: This allows you to define the expression to be used to exclude matches (optional).
  • match_mapping_type: This controls the types of the matched fields. For example, string, integer, and so on (optional).
  • path_match: This allows you to match the dynamic template against the full dot notation of the field, for example, obj1.*.value (optional).
  • path_unmatch: This will do the opposite of path_match, excluding the matched fields (optional).
  • match_pattern: This allows you to switch the matchers to regex (regular expression); otherwise, the glob pattern match is used (optional).

The dynamic template mapping part is a standard one, but with the ability to use special placeholders, such as the following:

  • {name}: This will be replaced with the actual dynamic field name
  • {dynamic_type}: This will be replaced with the type of the matched field
The order of the dynamic templates is very important; only the first one that is matched is executed. It is good practice to order the ones with more strict rule s first, and then the others.