ignore-malformed.asciidoc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 datatype 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
  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/_doc/1
  28. {
  29. "text": "Some text value",
  30. "number_one": "foo" <1>
  31. }
  32. PUT my_index/_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. <<date>>:: `date`
  44. <<date_nanos>>:: `date_nanos`
  45. <<geo-point>>:: `geo_point` for lat/lon points
  46. <<geo-shape>>:: `geo_shape` for complex shapes like polygons
  47. <<ip>>:: `ip` for IPv4 and IPv6 addresses
  48. TIP: The `ignore_malformed` setting value can be updated on
  49. existing fields using the <<indices-put-mapping,PUT mapping API>>.
  50. [[ignore-malformed-setting]]
  51. ==== Index-level default
  52. The `index.mapping.ignore_malformed` setting can be set on the index level to
  53. ignore malformed content globally across all allowed mapping types.
  54. Mapping types that don't support the setting will ignore it if set on the index level.
  55. [source,console]
  56. --------------------------------------------------
  57. PUT my_index
  58. {
  59. "settings": {
  60. "index.mapping.ignore_malformed": true <1>
  61. },
  62. "mappings": {
  63. "properties": {
  64. "number_one": { <1>
  65. "type": "byte"
  66. },
  67. "number_two": {
  68. "type": "integer",
  69. "ignore_malformed": false <2>
  70. }
  71. }
  72. }
  73. }
  74. --------------------------------------------------
  75. <1> The `number_one` field inherits the index-level setting.
  76. <2> The `number_two` field overrides the index-level setting to turn off `ignore_malformed`.
  77. ==== Dealing with malformed fields
  78. Malformed fields are silently ignored at indexing time when `ignore_malformed`
  79. is turned on. Whenever possible it is recommended to keep the number of
  80. documents that have a malformed field contained, or queries on this field will
  81. become meaningless. Elasticsearch makes it easy to check how many documents
  82. have malformed fields by using `exists`,`term` or `terms` queries on the special
  83. <<mapping-ignored-field,`_ignored`>> field.
  84. [[json-object-limits]]
  85. ==== Limits for JSON Objects
  86. You can't use `ignore_malformed` with the following datatypes:
  87. * <<nested, Nested datatype>>
  88. * <<object, Object datatype>>
  89. * <<range, Range datatypes>>
  90. You also can't use `ignore_malformed` to ignore JSON objects submitted to fields
  91. of the wrong datatype. A JSON object is any data surrounded by curly brackets
  92. `"{}"` and includes data mapped to the nested, object, and range datatypes.
  93. If you submit a JSON object to an unsupported field, {es} will return an error
  94. and reject the entire document regardless of the `ignore_malformed` setting.