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 to help improve its guessing capabilities.
Getting ready
You need a working ElasticSearch cluster.
How to do it...
We can extend the previous mapping 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", "mapping":{"type":" {dynamic_type}", "store":true} }} ], "properties" : {…} } }
How it works...
The root object (document) controls the behavior of its fields and all its children object fields.
In the document mapping we can define:
index_analyzer
: This defines the analyzer to be used for indexing within this document...