default-mapping.asciidoc 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. // AUTOSENSE
  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. "template": "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": "string",
  53. "fields": {
  54. "raw": {
  55. "type": "string",
  56. "index": "not_analyzed",
  57. "ignore_above": 256
  58. }
  59. }
  60. }
  61. }
  62. }
  63. ]
  64. }
  65. }
  66. }
  67. PUT logs-2015.10.01/event/1
  68. { "message": "error:16" }
  69. --------------------------------------------------
  70. // AUTOSENSE
  71. <1> The `logging` template will match any indices beginning with `logs-`.
  72. <2> Matching indices will be created with a single primary shard.
  73. <3> The `_all` field will be disabled by default for new type mappings.
  74. <4> String fields will be created with an `analyzed` main field, and a `not_analyzed` `.raw` field.