ignore_malformed(忽略格式不对的数据)

原文链接 : 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

贡献者 : 程威ApacheCNApache中文网

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

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

  1. curl -XPUT 'localhost:9200/my_index?pretty' -H 'Content-Type: application/json' -d'
  2. {
  3. "mappings": {
  4. "my_type": {
  5. "properties": {
  6. "number_one": {
  7. "type": "integer",
  8. "ignore_malformed": true
  9. },
  10. "number_two": {
  11. "type": "integer"
  12. }
  13. }
  14. }
  15. }
  16. }
  17. '
  18. curl -XPUT 'localhost:9200/my_index/my_type/1?pretty' -H 'Content-Type: application/json' -d'
  19. {
  20. "text": "Some text value",
  21. "number_one": "foo"
  22. }
  23. '
  24. curl -XPUT 'localhost:9200/my_index/my_type/2?pretty' -H 'Content-Type: application/json' -d'
  25. {
  26. "text": "Some text value",
  27. "number_two": "foo"
  28. }
  29. '

| 1 | 这个 document(文档)会索引text 字段,但不是 number_one 字段。 | | 2 | 这个 document(文档)会拒绝请求因为 number_two 不允许格式不正确的值. |

ignore_malformed设置允许在相同索引中相同名称的字段有不同的设置。可以使用 PUT mapping API 在现有字段上更新其值。

Index-level default

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

  1. curl -XPUT 'localhost:9200/my_index?pretty' -H 'Content-Type: application/json' -d'
  2. {
  3. "settings": {
  4. "index.mapping.ignore_malformed": true # 1
  5. },
  6. "mappings": {
  7. "my_type": {
  8. "properties": {
  9. "number_one": { # 2
  10. "type": "byte"
  11. },
  12. "number_two": {
  13. "type": "integer",
  14. "ignore_malformed": false # 3
  15. }
  16. }
  17. }
  18. }
  19. }
  20. '

| 12 | number_one 字段 继承 index-level 的配置. | | 3 | number_two 字段 覆盖 index-level 配置来关闭 ignore_malformed 设置. |

目录 3 - 标题 2

正文3

目录 N - 标题 2

正文4