Sometimes you don’t have much control over the data that you receive. One
user may send a login
field that is a 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:
PUT my_index { "mappings": { "properties": { "number_one": { "type": "integer", "ignore_malformed": true }, "number_two": { "type": "integer" } } } } PUT my_index/_doc/1 { "text": "Some text value", "number_one": "foo" } PUT my_index/_doc/2 { "text": "Some text value", "number_two": "foo" }
This document will have the | |
This document will be rejected because |
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 PUT mapping API.
The index.mapping.ignore_malformed
setting can be set on the index level to
allow to ignore malformed content globally across all mapping types.
Malformed fields are silently ignored at indexing time when ignore_malformed
is turned on. Whenever possible it is recommended to keep the number of
documents that have a malformed field contained, or queries on this field will
become meaningless. Elasticsearch makes it easy to check how many documents
have malformed fields by using exist
or term
queries on the special
_ignored
field.
You can’t use ignore_malformed
with the following datatypes:
You also can’t use ignore_malformed
to ignore JSON objects submitted to fields
of the wrong datatype. A JSON object is any data surrounded by curly brackets
"{}"
and includes data mapped to the nested, object, and range datatypes.
If you submit a JSON object to an unsupported field, Elasticsearch will return an error
and reject the entire document regardless of the ignore_malformed
setting.