Dynamic Mapping

edit

Dynamic Mapping

edit

Default mappings allow to automatically apply generic mapping definition to types that do not have mapping pre defined. This is mainly done thanks to the fact that the object mapping and namely the root object mapping allow for schema-less dynamic addition of unmapped fields.

The default mapping definition is plain mapping definition that is embedded within the distribution:

{
    "_default_" : {
    }
}

Pretty short, no? Basically, everything is defaulted, especially the dynamic nature of the root object mapping. The default mapping definition can be overridden in several manners. The simplest manner is to simply define a file called default-mapping.json and placed it under the config directory (which can be configured to exist in a different location). It can also be explicitly set using the index.mapper.default_mapping_location setting.

The dynamic creation of mappings for unmapped types can be completely disabled by setting index.mapper.dynamic to false.

The dynamic creation of fields within a type can be completely disabled by setting the dynamic property of the type to strict.

Here is a Put Mapping example that disables dynamic field creation for a tweet:

$ curl -XPUT 'http://localhost:9200/twitter/tweet/_mapping' -d '
{
    "tweet" : {
        "dynamic": "strict",
        "properties" : {
            "message" : {"type" : "string", "store" : "yes"}
        }
    }
}
'

Here is how we can change the default date_formats used in the root and inner object types:

{
    "_default_" : {
        "date_formats" : ["yyyy-MM-dd", "dd-MM-yyyy", "date_optional_time"]
    }
}