put-mapping.asciidoc 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. [[indices-put-mapping]]
  2. == Put Mapping
  3. The put mapping API allows to register specific mapping definition for a
  4. specific type.
  5. [source,js]
  6. --------------------------------------------------
  7. $ curl -XPUT 'http://localhost:9200/twitter/tweet/_mapping' -d '
  8. {
  9. "tweet" : {
  10. "properties" : {
  11. "message" : {"type" : "string", "store" : true }
  12. }
  13. }
  14. }
  15. '
  16. --------------------------------------------------
  17. The above example creates a mapping called `tweet` within the `twitter`
  18. index. The mapping simply defines that the `message` field should be
  19. stored (by default, fields are not stored, just indexed) so we can
  20. retrieve it later on using selective loading.
  21. More information on how to define type mappings can be found in the
  22. <<mapping,mapping>> section.
  23. [float]
  24. [[merging-conflicts]]
  25. === Merging & Conflicts
  26. When an existing mapping already exists under the given type, the two
  27. mapping definitions, the one already defined, and the new ones are
  28. merged. The `ignore_conflicts` parameters can be used to control if
  29. conflicts should be ignored or not, by default, it is set to `false`
  30. which means conflicts are *not* ignored.
  31. The definition of conflict is really dependent on the type merged, but
  32. in general, if a different core type is defined, it is considered as a
  33. conflict. New mapping definitions can be added to object types, and core
  34. type mappings can be upgraded by specifying multi fields on a core type.
  35. [float]
  36. [[put-mapping-multi-index]]
  37. === Multi Index
  38. The put mapping API can be applied to more than one index with a single
  39. call, or even on `_all` the indices.
  40. [source,js]
  41. --------------------------------------------------
  42. $ curl -XPUT 'http://localhost:9200/kimchy,elasticsearch/tweet/_mapping' -d '
  43. {
  44. "tweet" : {
  45. "properties" : {
  46. "message" : {"type" : "string", "store" : true }
  47. }
  48. }
  49. }
  50. '
  51. --------------------------------------------------
  52. All options:
  53. [source,js]
  54. --------------------------------------------------
  55. PUT /{index}/_mapping/{type}
  56. --------------------------------------------------
  57. where
  58. [horizontal]
  59. `{index}`:: `blank | * | _all | glob pattern | name1, name2, …`
  60. `{type}`:: Name of the type to add. Must be the name of the type defined in the body.
  61. Instead of `_mapping` you can also use the plural `_mappings`.
  62. The uri `PUT /{index}/{type}/_mapping` is still supported for backwards compatibility.