ignore-malformed.asciidoc 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. "_doc": {
  17. "properties": {
  18. "number_one": {
  19. "type": "integer",
  20. "ignore_malformed": true
  21. },
  22. "number_two": {
  23. "type": "integer"
  24. }
  25. }
  26. }
  27. }
  28. }
  29. PUT my_index/_doc/1
  30. {
  31. "text": "Some text value",
  32. "number_one": "foo" <1>
  33. }
  34. PUT my_index/_doc/2
  35. {
  36. "text": "Some text value",
  37. "number_two": "foo" <2>
  38. }
  39. --------------------------------------------------
  40. // CONSOLE
  41. // TEST[catch:bad_request]
  42. <1> This document will have the `text` field indexed, but not the `number_one` field.
  43. <2> This document will be rejected because `number_two` does not allow malformed values.
  44. TIP: The `ignore_malformed` setting is allowed to have different settings for
  45. fields of the same name in the same index. Its value can be updated on
  46. existing fields using the <<indices-put-mapping,PUT mapping API>>.
  47. [[ignore-malformed-setting]]
  48. ==== Index-level default
  49. The `index.mapping.ignore_malformed` setting can be set on the index level to
  50. allow to ignore malformed content globally across all mapping types.
  51. [source,js]
  52. --------------------------------------------------
  53. PUT my_index
  54. {
  55. "settings": {
  56. "index.mapping.ignore_malformed": true <1>
  57. },
  58. "mappings": {
  59. "_doc": {
  60. "properties": {
  61. "number_one": { <1>
  62. "type": "byte"
  63. },
  64. "number_two": {
  65. "type": "integer",
  66. "ignore_malformed": false <2>
  67. }
  68. }
  69. }
  70. }
  71. }
  72. --------------------------------------------------
  73. // CONSOLE
  74. <1> The `number_one` field inherits the index-level setting.
  75. <2> The `number_two` field overrides the index-level setting to turn off `ignore_malformed`.
  76. ==== Dealing with malformed fields
  77. Malformed fields are silently ignored at indexing time when `ignore_malformed`
  78. is turned on. Whenever possible it is recommended to keep the number of
  79. documents that have a malformed field contained, or queries on this field will
  80. become meaningless. Elasticsearch makes it easy to check how many documents
  81. have malformed fields by using `exist` or `term` queries on the special
  82. <<mapping-ignored-field,`_ignored`>> field.