Link Search Menu Expand Document Documentation Menu

Ignore malformed

The ignore_malformed mapping parameter instructs the indexing engine to ignore values that do not match the field’s expected format. When enabled, malformed values are not indexed, preventing entire-document rejection because of data format issues. This ensures that documents are still stored even if one or more fields contain data that cannot be parsed.

By default, ignore_malformed is disabled, which means that if a value cannot be parsed according to the field type, indexing will fail for the entire document.

Example: ignore_malformed off

Create an index named people_no_ignore containing an age field of type integer. By default, ignore_malformed is set to false:

PUT /people_no_ignore
{
  "mappings": {
    "properties": {
      "age": {
        "type": "integer"
      }
    }
  }
}

Index a document with a malformed value:

PUT /people_no_ignore/_doc/1
{
  "age": "twenty"
}

The request fails because of the malformed value:

{
  "error": {
    "root_cause": [
      {
        "type": "mapper_parsing_exception",
        "reason": "failed to parse field [age] of type [integer] in document with id '1'. Preview of field's value: 'twenty'"
      }
    ],
    "type": "mapper_parsing_exception",
    "reason": "failed to parse field [age] of type [integer] in document with id '1'. Preview of field's value: 'twenty'",
    "caused_by": {
      "type": "number_format_exception",
      "reason": "For input string: \"twenty\""
    }
  },
  "status": 400
}

Example: ignore_malformed on

Create an index named people_ignore in which the age field has ignore_malformed set to true:

PUT /people_ignore
{
  "mappings": {
    "properties": {
      "age": {
        "type": "integer",
        "ignore_malformed": true
      }
    }
  }
}

Index a document with a malformed value:

PUT /people_ignore/_doc/1
{
  "age": "twenty"
}

Retrieve the document:

GET /people_ignore/_doc/1

The response shows that the document was indexed successfully, despite having a malformed value:

{
  "_index": "people_ignore",
  "_id": "1",
  "_version": 1,
  "_seq_no": 0,
  "_primary_term": 1,
  "found": true,
  "_source": {
    "age": "twenty"
  }
}
350 characters left

Have a question? .

Want to contribute? or .