Using dynamic templates in document mapping
In the Using explicit mapping creation recipe, we saw how ElasticSearch is able to guess the field type using reflection. In this recipe, we'll see how we can help it to improve its guessing capabilities via dynamic templates.
The dynamic template feature is very useful, for example, if you need to create several indices with similar types, because it allows you to remove the need to define mappings from coded initial routines to automatic index document creation. A typical use is to define types for logstash log indices.
Getting ready
You need a working ElasticSearch cluster.
How to do it...
You can extend the previous mapping by adding document-related settings:
{ "order" : { "index_analyzer":"standard", "search_analyzer":"standard", "dynamic_date_formats":["yyyy-MM-dd", "dd-MM-yyyy"], "date_detection":true, "numeric_detection":true, "dynamic_templates":[ {"template1":{ "match":"*", "match_mapping_type":"long...