You're viewing version 2.19 of the OpenSearch documentation. For the latest version, see the current documentation. For information about OpenSearch version maintenance, see Release Schedule and Maintenance Policy.
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"
}
}