2013-08-28 19:24:34 -04:00
|
|
|
[[mapping-dynamic-mapping]]
|
|
|
|
== Dynamic Mapping
|
|
|
|
|
2014-05-20 07:33:53 -04:00
|
|
|
Default mappings allow generic mapping definitions to be automatically applied
|
2014-03-07 08:21:45 -05:00
|
|
|
to types that do not have mappings predefined. This is mainly done
|
2013-08-28 19:24:34 -04:00
|
|
|
thanks to the fact that the
|
|
|
|
<<mapping-object-type,object mapping>> and
|
|
|
|
namely the <<mapping-root-object-type,root
|
|
|
|
object mapping>> allow for schema-less dynamic addition of unmapped
|
|
|
|
fields.
|
|
|
|
|
2014-03-07 08:21:45 -05:00
|
|
|
The default mapping definition is a plain mapping definition that is
|
2013-08-28 19:24:34 -04:00
|
|
|
embedded within the distribution:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
{
|
|
|
|
"_default_" : {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
2014-03-07 08:21:45 -05:00
|
|
|
Pretty short, isn't it? Basically, everything is defaulted, especially the
|
2015-04-29 03:29:32 -04:00
|
|
|
dynamic nature of the root object mapping. The default mapping can be
|
|
|
|
overridden by specifying the `_default_` type when creating a new index.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
The dynamic creation of mappings for unmapped types can be completely
|
|
|
|
disabled by setting `index.mapper.dynamic` to `false`.
|
|
|
|
|
2013-10-10 14:17:49 -04:00
|
|
|
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 <<indices-put-mapping,Put Mapping>> example that
|
|
|
|
disables dynamic field creation for a `tweet`:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
2014-10-01 09:13:38 -04:00
|
|
|
$ curl -XPUT 'http://localhost:9200/twitter/_mapping/tweet' -d '
|
2013-10-10 14:17:49 -04:00
|
|
|
{
|
|
|
|
"tweet" : {
|
|
|
|
"dynamic": "strict",
|
|
|
|
"properties" : {
|
2013-11-07 10:56:59 -05:00
|
|
|
"message" : {"type" : "string", "store" : true }
|
2013-10-10 14:17:49 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
Here is how we can change the default
|
2013-08-28 19:24:34 -04:00
|
|
|
<<mapping-date-format,date_formats>> used in the
|
|
|
|
root and inner object types:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
{
|
|
|
|
"_default_" : {
|
2014-04-13 08:28:24 -04:00
|
|
|
"dynamic_date_formats" : ["yyyy-MM-dd", "dd-MM-yyyy", "date_optional_time"]
|
2013-08-28 19:24:34 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2014-07-18 16:50:07 -04:00
|
|
|
|
|
|
|
[float]
|
|
|
|
=== Unmapped fields in queries
|
|
|
|
|
2014-11-11 10:09:39 -05:00
|
|
|
Queries and filters can refer to fields that don't exist in a mapping. Whether this
|
|
|
|
is allowed is controlled by the `index.query.parse.allow_unmapped_fields` setting.
|
|
|
|
This setting defaults to `true`. Setting it to `false` will disallow the usage of
|
|
|
|
unmapped fields in queries.
|
2014-07-18 16:50:07 -04:00
|
|
|
|
2014-11-11 10:09:39 -05:00
|
|
|
When registering a new <<search-percolate,percolator query>> or creating
|
|
|
|
a <<filtered,filtered alias>> then the `index.query.parse.allow_unmapped_fields` setting
|
|
|
|
is forcefully overwritten to disallowed unmapped fields.
|