Using dynamic templates in document mapping
In the Using explicit mapping creation recipe, we have seen how Elasticsearch is able to guess the field type using reflection. In this recipe, we'll see how to help it to improve its guessing capabilities via dynamic templates.
Dynamic template feature is very useful, for example, if you need to create several indices, with similar types, because it allows moving the need to define mappings from coded initial routines to automatic index-document creation. A typical usage is to define types for Logstash log indices.
Getting ready
You need an up-and-running Elasticsearch installation as we described in the Downloading and installing Elasticsearch recipe in Chapter 2, Downloading and Setup.
To execute curl
via the command line, you need to install curl
for your operative system.
How to do it...
We can extend the previous mapping adding document-related settings:
{ "order" : { "dynamic_date_formats":["yyyy-MM-dd", "dd-MM-yyyy"], ...