<commit_before>[[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": {
    "_doc": {
      "properties": {
        "number_one": {
          "type": "integer",
          "ignore_malformed": true
        },
        "number_two": {
          "type": "integer"
        }
      }
    }
  }
}

PUT my_index/_doc/1
{
  "text":       "Some text value",
  "number_one": "foo" <1>
}

PUT my_index/_doc/2
{
  "text":       "Some text value",
  "number_two": "foo" <2>
}
--------------------------------------------------
// CONSOLE
// TEST[catch:bad_request]
<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.

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>>.


[[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": {
    "_doc": {
      "properties": {
        "number_one": { <1>
          "type": "byte"
        },
        "number_two": {
          "type": "integer",
          "ignore_malformed": false <2>
        }
      }
    }
  }
}
--------------------------------------------------
// CONSOLE

<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`.

==== Dealing with malformed fields

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
<<mapping-ignored-field,`_ignored`>> field.
<commit_msg>[DOCS] Document limits for JSON objects with `ignore_malformed` mapping setting (#40976)<commit_after>[[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": {
    "_doc": {
      "properties": {
        "number_one": {
          "type": "integer",
          "ignore_malformed": true
        },
        "number_two": {
          "type": "integer"
        }
      }
    }
  }
}

PUT my_index/_doc/1
{
  "text":       "Some text value",
  "number_one": "foo" <1>
}

PUT my_index/_doc/2
{
  "text":       "Some text value",
  "number_two": "foo" <2>
}
--------------------------------------------------
// CONSOLE
// TEST[catch:bad_request]
<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.

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>>.


[[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": {
    "_doc": {
      "properties": {
        "number_one": { <1>
          "type": "byte"
        },
        "number_two": {
          "type": "integer",
          "ignore_malformed": false <2>
        }
      }
    }
  }
}
--------------------------------------------------
// CONSOLE

<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`.

==== Dealing with malformed fields

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
<<mapping-ignored-field,`_ignored`>> field.

==== Limits for JSON Objects
You can't use `ignore_malformed` with the following datatypes:

* <<nested, Nested datatype>>
* <<object, Object datatype>>
* <<range, Range 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, {es} will return an error
and reject the entire document regardless of the `ignore_malformed` setting.
{'fraction_non_alphanumeric': 0.15777706802938357, 'fraction_numerical': 0.004311721494730118, 'mean_word_length': 2.6476412347117066, 'pattern_counts': {'":': 44, '<': 39, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1213515', 'n_tokens_mistral': 1755, 'n_tokens_neox': 1729, 'n_words': 711}