> For the complete documentation index, see [llms.txt](https://xiaoxiami.gitbook.io/elasticsearch/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://xiaoxiami.gitbook.io/elasticsearch/ji-chu/mapping/323mapping-parametersff08-ying-she-can-shu-ff09/ignoremalformed-ff08-hu-lve-ge-shi-bu-dui-de-shu-ju-ff09.md).

# ignore\_malformed（忽略格式不对的数据）

有时候你对接受到的数据不会有太多的控制.一个用户可能发送一个日期类型的登录字段,另一个用户发送一个邮箱地址的登录字段.

尝试将错误的数据类型索引到字段中,默认情况会抛出异常,并拒绝整个**document**（文档）.**ignore\_malformed** 参数（如果设置为true）允许忽略该异常。格式不正确的字段不会被索引，但文档中的其他字段正常处理。

```
curl -XPUT 'localhost:9200/my_index?pretty' -H 'Content-Type: application/json' -d'
{
  "mappings": {
    "my_type": {
      "properties": {
        "number_one": {
          "type": "integer",
          "ignore_malformed": true
        },
        "number_two": {
          "type": "integer"
        }
      }
    }
  }
}
'
curl -XPUT 'localhost:9200/my_index/my_type/1?pretty' -H 'Content-Type: application/json' -d'
{
  "text":       "Some text value",
  "number_one": "foo"
}
'
curl -XPUT 'localhost:9200/my_index/my_type/2?pretty' -H 'Content-Type: application/json' -d'
{
  "text":       "Some text value",
  "number_two": "foo"
}
'
```

| 1 | 这个**document**（文档）会索引text 字段,但不是**number\_one**字段。  |
| - | --------------------------------------------------- |
| 2 | 这个**document**（文档）会拒绝请求因为**number\_two**不允许格式不正确的值. |

> ignore\_malformed设置允许在相同索引中相同名称的字段有不同的设置。可以使用 [PUT mapping API](https://www.elastic.co/guide/en/elasticsearch/reference/5.3/indices-put-mapping.html) 在现有字段上更新其值。

## Index-level default

可以在索引级别上设置 **index.mapping.ignore\_malformed** 的配置,以允许在所有映射类型中全局忽略格式错误的内容.

```
curl -XPUT 'localhost:9200/my_index?pretty' -H 'Content-Type: application/json' -d'
{
  "settings": {
    "index.mapping.ignore_malformed": true  # 1
  },
  "mappings": {
    "my_type": {
      "properties": {
        "number_one": {  # 2
          "type": "byte"
        },
        "number_two": {
          "type": "integer",
          "ignore_malformed": false  # 3
        }
      }
    }
  }
}
'
```

| 1, 2 | **number\_one**字段 继承**index-level**的配置.                          |
| ---- | ---------------------------------------------------------------- |
| 3    | **number\_two**字段 覆盖**index-level**配置来关闭**ignore\_malformed**设置. |
