default-mapping.asciidoc 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. While the `_default_` mapping can be updated after an index has been created,
  32. the new defaults will only affect mapping types that are created afterwards.
  33. The `_default_` mapping can be used in conjunction with
  34. <<indices-templates,Index templates>> to control dynamically created types
  35. within automatically created indices:
  36. [source,js]
  37. --------------------------------------------------
  38. PUT _template/logging
  39. {
  40. "index_patterns": ["logs-*"], <1>
  41. "settings": { "number_of_shards": 1 }, <2>
  42. "mappings": {
  43. "_default_": {
  44. "_all": { <3>
  45. "enabled": false
  46. },
  47. "dynamic_templates": [
  48. {
  49. "strings": { <4>
  50. "match_mapping_type": "string",
  51. "mapping": {
  52. "type": "text",
  53. "fields": {
  54. "raw": {
  55. "type": "keyword",
  56. "ignore_above": 256
  57. }
  58. }
  59. }
  60. }
  61. }
  62. ]
  63. }
  64. }
  65. }
  66. PUT logs-2015.10.01/event/1
  67. { "message": "error:16" }
  68. --------------------------------------------------
  69. // CONSOLE
  70. <1> The `logging` template will match any indices beginning with `logs-`.
  71. <2> Matching indices will be created with a single primary shard.
  72. <3> The `_all` field will be disabled by default for new type mappings.
  73. <4> String fields will be created with a `text` main field, and a `keyword` `.raw` field.