dynamic-mapping.asciidoc 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. [[mapping-dynamic-mapping]]
  2. == Dynamic Mapping
  3. Default mappings allow to automatically apply generic mapping definitions
  4. to types that do not have mappings predefined. This is mainly done
  5. thanks to the fact that the
  6. <<mapping-object-type,object mapping>> and
  7. namely the <<mapping-root-object-type,root
  8. object mapping>> allow for schema-less dynamic addition of unmapped
  9. fields.
  10. The default mapping definition is a plain mapping definition that is
  11. embedded within the distribution:
  12. [source,js]
  13. --------------------------------------------------
  14. {
  15. "_default_" : {
  16. }
  17. }
  18. --------------------------------------------------
  19. Pretty short, isn't it? Basically, everything is defaulted, especially the
  20. dynamic nature of the root object mapping. The default mapping
  21. definition can be overridden in several manners. The simplest manner is
  22. to simply define a file called `default-mapping.json` and to place it
  23. under the `config` directory (which can be configured to exist in a
  24. different location). It can also be explicitly set using the
  25. `index.mapper.default_mapping_location` setting.
  26. The dynamic creation of mappings for unmapped types can be completely
  27. disabled by setting `index.mapper.dynamic` to `false`.
  28. The dynamic creation of fields within a type can be completely
  29. disabled by setting the `dynamic` property of the type to `strict`.
  30. Here is a <<indices-put-mapping,Put Mapping>> example that
  31. disables dynamic field creation for a `tweet`:
  32. [source,js]
  33. --------------------------------------------------
  34. $ curl -XPUT 'http://localhost:9200/twitter/tweet/_mapping' -d '
  35. {
  36. "tweet" : {
  37. "dynamic": "strict",
  38. "properties" : {
  39. "message" : {"type" : "string", "store" : true }
  40. }
  41. }
  42. }
  43. '
  44. --------------------------------------------------
  45. Here is how we can change the default
  46. <<mapping-date-format,date_formats>> used in the
  47. root and inner object types:
  48. [source,js]
  49. --------------------------------------------------
  50. {
  51. "_default_" : {
  52. "date_formats" : ["yyyy-MM-dd", "dd-MM-yyyy", "date_optional_time"]
  53. }
  54. }
  55. --------------------------------------------------