Skip to content

Commit 94f1aa0

Browse files
adding ignore_malformed field parameter (#9513) (#9619)
1 parent 823b98a commit 94f1aa0

2 files changed

Lines changed: 120 additions & 1 deletion

File tree

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
---
2+
layout: default
3+
title: Ignore malformed
4+
parent: Mapping parameters
5+
grand_parent: Mapping and field types
6+
nav_order: 45
7+
has_children: false
8+
has_toc: false
9+
---
10+
11+
# Ignore malformed
12+
13+
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.
14+
15+
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.
16+
17+
## Example: ignore_malformed off
18+
19+
Create an index named `people_no_ignore` containing an `age` field of type `integer`. By default, `ignore_malformed` is set to `false`:
20+
21+
```json
22+
PUT /people_no_ignore
23+
{
24+
"mappings": {
25+
"properties": {
26+
"age": {
27+
"type": "integer"
28+
}
29+
}
30+
}
31+
}
32+
```
33+
{% include copy-curl.html %}
34+
35+
Index a document with a malformed value:
36+
37+
```json
38+
PUT /people_no_ignore/_doc/1
39+
{
40+
"age": "twenty"
41+
}
42+
```
43+
{% include copy-curl.html %}
44+
45+
The request fails because of the malformed value:
46+
47+
```json
48+
{
49+
"error": {
50+
"root_cause": [
51+
{
52+
"type": "mapper_parsing_exception",
53+
"reason": "failed to parse field [age] of type [integer] in document with id '1'. Preview of field's value: 'twenty'"
54+
}
55+
],
56+
"type": "mapper_parsing_exception",
57+
"reason": "failed to parse field [age] of type [integer] in document with id '1'. Preview of field's value: 'twenty'",
58+
"caused_by": {
59+
"type": "number_format_exception",
60+
"reason": "For input string: \"twenty\""
61+
}
62+
},
63+
"status": 400
64+
}
65+
```
66+
67+
## Example: ignore_malformed on
68+
69+
Create an index named `people_ignore` in which the `age` field has `ignore_malformed` set to `true`:
70+
71+
```json
72+
PUT /people_ignore
73+
{
74+
"mappings": {
75+
"properties": {
76+
"age": {
77+
"type": "integer",
78+
"ignore_malformed": true
79+
}
80+
}
81+
}
82+
}
83+
```
84+
{% include copy-curl.html %}
85+
86+
Index a document with a malformed value:
87+
88+
```json
89+
PUT /people_ignore/_doc/1
90+
{
91+
"age": "twenty"
92+
}
93+
```
94+
{% include copy-curl.html %}
95+
96+
Retrieve the document:
97+
98+
```json
99+
GET /people_ignore/_doc/1
100+
```
101+
{% include copy-curl.html %}
102+
103+
The response shows that the document was indexed successfully, despite having a malformed value:
104+
105+
```json
106+
{
107+
"_index": "people_ignore",
108+
"_id": "1",
109+
"_version": 1,
110+
"_seq_no": 0,
111+
"_primary_term": 1,
112+
"found": true,
113+
"_source": {
114+
"age": "twenty"
115+
}
116+
}
117+
```
118+
119+

_field-types/mapping-parameters/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ Parameter | Description
2323
`enabled` | Specifies whether the field is enabled or disabled. Default value is `true`, which means that the field is enabled. Allowed values are `true` or `false`.
2424
`format` | Specifies the date format for date fields. There is no default value for this parameter. Allowed values are any valid date format string, such as `yyyy-MM-dd` or `epoch_millis`.
2525
`ignore_above` | Skips indexing values that exceed the specified length. Default value is `2147483647`, which means that there is no limit on the field value length. Allowed values are any positive integer.
26-
`ignore_malformed` | Specifies whether malformed values should be ignored. Default value is `false`, which means that malformed values are not ignored. Allowed values are `true` or `false`.
26+
[`ignore_malformed`]({{site.url}}{{site.baseurl}}/field-types/mapping-parameters/ignore-malformed/) | Specifies whether malformed values should be ignored. Default value is `false`, which means that malformed values are not ignored. Allowed values are `true` or `false`.
2727
`index` | Specifies whether a field should be indexed. Default value is `true`, which means that the field is indexed. Allowed values are `true` or `false`.
2828
`index_options` | Specifies what information should be stored in an index for scoring purposes. Default value is `docs`, which means that only the document numbers are stored in the index. Allowed values are `docs`, `freqs`, `positions`, or `offsets`.

0 commit comments

Comments
 (0)