default-mapping.asciidoc 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. [[default-mapping]]
  2. === `_default_` mapping
  3. The default mapping, which will be used as the base mapping for any new
  4. mapping types, can be customised by adding a mapping type with the name
  5. `_default_` to an index, either when
  6. <<indices-create-index,creating the index>> or later on with the
  7. <<indices-put-mapping,PUT mapping>> API.
  8. [source,js]
  9. --------------------------------------------------
  10. PUT my_index
  11. {
  12. "mappings": {
  13. "_default_": { <1>
  14. "_all": {
  15. "enabled": false
  16. }
  17. },
  18. "user": {}, <2>
  19. "blogpost": { <3>
  20. "_all": {
  21. "enabled": true
  22. }
  23. }
  24. }
  25. }
  26. --------------------------------------------------
  27. // CONSOLE
  28. <1> The `_default_` mapping defaults the <<mapping-all-field,`_all`>> field to disabled.
  29. <2> The `user` type inherits the settings from `_default_`.
  30. <3> The `blogpost` type overrides the defaults and enables the <<mapping-all-field,`_all`>> field.
  31. NOTE: When updating the `_default_` mapping with the
  32. <<indices-put-mapping,PUT mapping>> API, the new mapping is not merged with
  33. the existing mapping. Instead, the new `_default_` mapping replaces the
  34. existing one.
  35. While the `_default_` mapping can be updated after an index has been created,
  36. the new defaults will only affect mapping types that are created afterwards.
  37. The `_default_` mapping can be used in conjunction with
  38. <<indices-templates,Index templates>> to control dynamically created types
  39. within automatically created indices:
  40. [source,js]
  41. --------------------------------------------------
  42. PUT _template/logging
  43. {
  44. "index_patterns": ["logs-*"], <1>
  45. "settings": { "number_of_shards": 1 }, <2>
  46. "mappings": {
  47. "_default_": {
  48. "_all": { <3>
  49. "enabled": false
  50. },
  51. "dynamic_templates": [
  52. {
  53. "strings": { <4>
  54. "match_mapping_type": "string",
  55. "mapping": {
  56. "type": "text",
  57. "fields": {
  58. "raw": {
  59. "type": "keyword",
  60. "ignore_above": 256
  61. }
  62. }
  63. }
  64. }
  65. }
  66. ]
  67. }
  68. }
  69. }
  70. PUT logs-2015.10.01/event/1
  71. { "message": "error:16" }
  72. --------------------------------------------------
  73. // CONSOLE
  74. <1> The `logging` template will match any indices beginning with `logs-`.
  75. <2> Matching indices will be created with a single primary shard.
  76. <3> The `_all` field will be disabled by default for new type mappings.
  77. <4> String fields will be created with a `text` main field, and a `keyword` `.raw` field.