企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# ignore_malformed(忽略格式不对的数据) 原文链接 : [https://www.elastic.co/guide/en/elasticsearch/reference/5.3/ignore-malformed.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.3/ignore-malformed.html) 译文链接 : [http://www.apache.wiki/pages/createpage-entervariables.action?templateId=4816898&spaceKey=Elasticsearch&title=&newSpaceKey=Elasticsearch&fromPageId=9405287](http://www.apache.wiki/pages/createpage-entervariables.action?templateId=4816898&spaceKey=Elasticsearch&title=&newSpaceKey=Elasticsearch&fromPageId=9405287) 贡献者 : [程威](/display/~chengwei),[ApacheCN](/display/~apachecn),[Apache中文网](/display/~apachechina) 有时候你对接受到的数据不会有太多的控制.一个用户可能发送一个日期类型的登录字段,另一个用户发送一个邮箱地址的登录字段. 尝试将错误的数据类型索引到字段中,默认情况会抛出异常,并拒绝整个 **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 "Put Mapping") 在现有字段上更新其值。 ## 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 } } } } } ' ``` | 12 |  **number_one** 字段 继承 **index-level** 的配置. | | 3 |  **number_two** 字段 覆盖 **index-level** 配置来关闭 **ignore_malformed** 设置. | ## 目录 3 - 标题 2 正文3 ## 目录 N - 标题 2 正文4