ignore-malformed.asciidoc 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. [[ignore-malformed]]
  2. === `ignore_malformed`
  3. Sometimes you don't have much control over the data that you receive. One
  4. user may send a `login` field that is a <<date,`date`>>, and another sends a
  5. `login` field that is an email address.
  6. Trying to index the wrong data type into a field throws an exception by
  7. default, and rejects the whole document. The `ignore_malformed` parameter, if
  8. set to `true`, allows the exception to be ignored. The malformed field is not
  9. indexed, but other fields in the document are processed normally.
  10. For example:
  11. [source,console]
  12. --------------------------------------------------
  13. PUT my-index-000001
  14. {
  15. "mappings": {
  16. "properties": {
  17. "number_one": {
  18. "type": "integer",
  19. "ignore_malformed": true
  20. },
  21. "number_two": {
  22. "type": "integer"
  23. }
  24. }
  25. }
  26. }
  27. PUT my-index-000001/_doc/1
  28. {
  29. "text": "Some text value",
  30. "number_one": "foo" <1>
  31. }
  32. PUT my-index-000001/_doc/2
  33. {
  34. "text": "Some text value",
  35. "number_two": "foo" <2>
  36. }
  37. --------------------------------------------------
  38. // TEST[catch:bad_request]
  39. <1> This document will have the `text` field indexed, but not the `number_one` field.
  40. <2> This document will be rejected because `number_two` does not allow malformed values.
  41. The `ignore_malformed` setting is currently supported by the following <<mapping-types,mapping types>>:
  42. <<number>>:: `long`, `integer`, `short`, `byte`, `double`, `float`, `half_float`, `scaled_float`
  43. <<boolean>>:: `boolean`
  44. <<date>>:: `date`
  45. <<date_nanos>>:: `date_nanos`
  46. <<geo-point>>:: `geo_point` for lat/lon points
  47. <<geo-shape>>:: `geo_shape` for complex shapes like polygons
  48. <<ip>>:: `ip` for IPv4 and IPv6 addresses
  49. TIP: The `ignore_malformed` setting value can be updated on
  50. existing fields using the <<indices-put-mapping,update mapping API>>.
  51. [[ignore-malformed-setting]]
  52. ==== Index-level default
  53. The `index.mapping.ignore_malformed` setting can be set on the index level to
  54. ignore malformed content globally across all allowed mapping types.
  55. Mapping types that don't support the setting will ignore it if set on the index level.
  56. [source,console]
  57. --------------------------------------------------
  58. PUT my-index-000001
  59. {
  60. "settings": {
  61. "index.mapping.ignore_malformed": true <1>
  62. },
  63. "mappings": {
  64. "properties": {
  65. "number_one": { <1>
  66. "type": "byte"
  67. },
  68. "number_two": {
  69. "type": "integer",
  70. "ignore_malformed": false <2>
  71. }
  72. }
  73. }
  74. }
  75. --------------------------------------------------
  76. <1> The `number_one` field inherits the index-level setting.
  77. <2> The `number_two` field overrides the index-level setting to turn off `ignore_malformed`.
  78. ==== Dealing with malformed fields
  79. Malformed fields are silently ignored at indexing time when `ignore_malformed`
  80. is turned on. Whenever possible it is recommended to keep the number of
  81. documents that have a malformed field contained, or queries on this field will
  82. become meaningless. Elasticsearch makes it easy to check how many documents
  83. have malformed fields by using `exists`,`term` or `terms` queries on the special
  84. <<mapping-ignored-field,`_ignored`>> field.
  85. [[json-object-limits]]
  86. ==== Limits for JSON Objects
  87. You can't use `ignore_malformed` with the following data types:
  88. * <<nested, Nested data type>>
  89. * <<object, Object data type>>
  90. * <<range, Range data types>>
  91. You also can't use `ignore_malformed` to ignore JSON objects submitted to fields
  92. of the wrong data type. A JSON object is any data surrounded by curly brackets
  93. `"{}"` and includes data mapped to the nested, object, and range data types.
  94. If you submit a JSON object to an unsupported field, {es} will return an error
  95. and reject the entire document regardless of the `ignore_malformed` setting.