ignore-malformed.asciidoc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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,js]
  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. // CONSOLE
  39. // TEST[catch:bad_request]
  40. <1> This document will have the `text` field indexed, but not the `number_one` field.
  41. <2> This document will be rejected because `number_two` does not allow malformed values.
  42. TIP: The `ignore_malformed` setting is allowed to have different settings for
  43. fields of the same name in the same index. Its value can be updated on
  44. existing fields using the <<indices-put-mapping,PUT mapping API>>.
  45. [[ignore-malformed-setting]]
  46. ==== Index-level default
  47. The `index.mapping.ignore_malformed` setting can be set on the index level to
  48. allow to ignore malformed content globally across all mapping types.
  49. [source,js]
  50. --------------------------------------------------
  51. PUT my_index
  52. {
  53. "settings": {
  54. "index.mapping.ignore_malformed": true <1>
  55. },
  56. "mappings": {
  57. "properties": {
  58. "number_one": { <1>
  59. "type": "byte"
  60. },
  61. "number_two": {
  62. "type": "integer",
  63. "ignore_malformed": false <2>
  64. }
  65. }
  66. }
  67. }
  68. --------------------------------------------------
  69. // CONSOLE
  70. <1> The `number_one` field inherits the index-level setting.
  71. <2> The `number_two` field overrides the index-level setting to turn off `ignore_malformed`.
  72. ==== Dealing with malformed fields
  73. Malformed fields are silently ignored at indexing time when `ignore_malformed`
  74. is turned on. Whenever possible it is recommended to keep the number of
  75. documents that have a malformed field contained, or queries on this field will
  76. become meaningless. Elasticsearch makes it easy to check how many documents
  77. have malformed fields by using `exist` or `term` queries on the special
  78. <<mapping-ignored-field,`_ignored`>> field.
  79. [[json-object-limits]]
  80. ==== Limits for JSON Objects
  81. You can't use `ignore_malformed` with the following datatypes:
  82. * <<nested, Nested datatype>>
  83. * <<object, Object datatype>>
  84. * <<range, Range datatypes>>
  85. You also can't use `ignore_malformed` to ignore JSON objects submitted to fields
  86. of the wrong datatype. A JSON object is any data surrounded by curly brackets
  87. `"{}"` and includes data mapped to the nested, object, and range datatypes.
  88. If you submit a JSON object to an unsupported field, {es} will return an error
  89. and reject the entire document regardless of the `ignore_malformed` setting.