dynamic.asciidoc 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. [[dynamic]]
  2. === `dynamic`
  3. When you index a document containing a new field, {es} <<dynamic-mapping,adds the field dynamically>> to a document or to inner objects within a document. The
  4. following document adds the string field `username`, the object field
  5. `name`, and two string fields under the `name` object:
  6. [source,console]
  7. ----
  8. PUT my-index-000001/_doc/1
  9. {
  10. "username": "johnsmith",
  11. "name": { <1>
  12. "first": "John",
  13. "last": "Smith"
  14. }
  15. }
  16. GET my-index-000001/_mapping <2>
  17. ----
  18. <1> Refer to fields under the `name` object as `name.first` and `name.last`.
  19. <2> Check the mapping to view changes.
  20. The following document adds two string fields: `email` and `name.middle`:
  21. [source,console]
  22. ----
  23. PUT my-index-000001/_doc/2
  24. {
  25. "username": "marywhite",
  26. "email": "mary@white.com",
  27. "name": {
  28. "first": "Mary",
  29. "middle": "Alice",
  30. "last": "White"
  31. }
  32. }
  33. GET my-index-000001/_mapping
  34. ----
  35. [[dynamic-inner-objects]]
  36. ==== Setting `dynamic` on inner objects
  37. <<object,Inner objects>> inherit the `dynamic` setting from their parent
  38. object or from the mapping type. In the following example, dynamic mapping is
  39. disabled at the type level, so no new top-level fields will be added
  40. dynamically.
  41. However, the `user.social_networks` object enables dynamic mapping, so you can
  42. add fields to this inner object.
  43. [source,console]
  44. ----
  45. PUT my-index-000001
  46. {
  47. "mappings": {
  48. "dynamic": false, <1>
  49. "properties": {
  50. "user": { <2>
  51. "properties": {
  52. "name": {
  53. "type": "text"
  54. },
  55. "social_networks": {
  56. "dynamic": true, <3>
  57. "properties": {}
  58. }
  59. }
  60. }
  61. }
  62. }
  63. }
  64. ----
  65. <1> Disables dynamic mapping at the type level.
  66. <2> The `user` object inherits the type-level setting.
  67. <3> Enables dynamic mapping for this inner object.
  68. [[dynamic-parameters]]
  69. ==== Parameters for `dynamic`
  70. The `dynamic` parameter controls whether new fields are added dynamically, and
  71. accepts the following parameters:
  72. [horizontal]
  73. `true`:: New fields are added to the mapping (default).
  74. `runtime`:: New fields are added to the mapping as <<runtime,runtime fields>>.
  75. These fields are not indexed, and are loaded from `_source` at query time.
  76. `false`:: New fields are ignored. These fields will not be indexed
  77. or searchable, but will still appear in the `_source` field of returned hits. These fields will not be added
  78. to the mapping, and new fields must be added explicitly.
  79. `strict`:: If new fields are detected, an exception is thrown and the document
  80. is rejected. New fields must be explicitly added to the mapping.