2015-08-06 11:24:29 -04:00
|
|
|
[[ignore-malformed]]
|
|
|
|
=== `ignore_malformed`
|
|
|
|
|
|
|
|
Sometimes you don't have much control over the data that you receive. One
|
|
|
|
user may send a `login` field that is a <<date,`date`>>, and another sends a
|
|
|
|
`login` field that is an email address.
|
|
|
|
|
|
|
|
Trying to index the wrong datatype into a field throws an exception by
|
|
|
|
default, and rejects the whole document. The `ignore_malformed` parameter, if
|
|
|
|
set to `true`, allows the exception to be ignored. The malformed field is not
|
|
|
|
indexed, but other fields in the document are processed normally.
|
|
|
|
|
|
|
|
For example:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
PUT my_index
|
|
|
|
{
|
|
|
|
"mappings": {
|
2017-12-14 11:47:53 -05:00
|
|
|
"_doc": {
|
2015-08-06 11:24:29 -04:00
|
|
|
"properties": {
|
|
|
|
"number_one": {
|
|
|
|
"type": "integer",
|
|
|
|
"ignore_malformed": true
|
2016-04-29 10:42:03 -04:00
|
|
|
},
|
|
|
|
"number_two": {
|
|
|
|
"type": "integer"
|
2015-08-06 11:24:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-14 11:47:53 -05:00
|
|
|
PUT my_index/_doc/1
|
2015-08-06 11:24:29 -04:00
|
|
|
{
|
|
|
|
"text": "Some text value",
|
|
|
|
"number_one": "foo" <1>
|
|
|
|
}
|
|
|
|
|
2017-12-14 11:47:53 -05:00
|
|
|
PUT my_index/_doc/2
|
2015-08-06 11:24:29 -04:00
|
|
|
{
|
|
|
|
"text": "Some text value",
|
|
|
|
"number_two": "foo" <2>
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2016-05-09 09:42:23 -04:00
|
|
|
// CONSOLE
|
2017-09-14 15:24:03 -04:00
|
|
|
// TEST[catch:bad_request]
|
2016-04-29 10:42:03 -04:00
|
|
|
<1> This document will have the `text` field indexed, but not the `number_one` field.
|
|
|
|
<2> This document will be rejected because `number_two` does not allow malformed values.
|
2015-08-06 11:24:29 -04:00
|
|
|
|
2015-08-12 15:21:37 -04:00
|
|
|
TIP: The `ignore_malformed` setting is allowed to have different settings for
|
|
|
|
fields of the same name in the same index. Its value can be updated on
|
|
|
|
existing fields using the <<indices-put-mapping,PUT mapping API>>.
|
|
|
|
|
2015-08-06 11:24:29 -04:00
|
|
|
|
|
|
|
[[ignore-malformed-setting]]
|
|
|
|
==== Index-level default
|
|
|
|
|
|
|
|
The `index.mapping.ignore_malformed` setting can be set on the index level to
|
|
|
|
allow to ignore malformed content globally across all mapping types.
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
PUT my_index
|
|
|
|
{
|
|
|
|
"settings": {
|
|
|
|
"index.mapping.ignore_malformed": true <1>
|
|
|
|
},
|
|
|
|
"mappings": {
|
2017-12-14 11:47:53 -05:00
|
|
|
"_doc": {
|
2015-08-06 11:24:29 -04:00
|
|
|
"properties": {
|
|
|
|
"number_one": { <1>
|
|
|
|
"type": "byte"
|
|
|
|
},
|
|
|
|
"number_two": {
|
|
|
|
"type": "integer",
|
|
|
|
"ignore_malformed": false <2>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2016-05-09 09:42:23 -04:00
|
|
|
// CONSOLE
|
2015-08-06 11:24:29 -04:00
|
|
|
|
|
|
|
<1> The `number_one` field inherits the index-level setting.
|
|
|
|
<2> The `number_two` field overrides the index-level setting to turn off `ignore_malformed`.
|