put-mapping.asciidoc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. [[indices-put-mapping]]
  2. == Put Mapping
  3. The PUT mapping API allows you to add fields to an existing index or to change search only settings of existing fields.
  4. [source,js]
  5. --------------------------------------------------
  6. PUT twitter <1>
  7. {}
  8. PUT twitter/_mapping <2>
  9. {
  10. "properties": {
  11. "email": {
  12. "type": "keyword"
  13. }
  14. }
  15. }
  16. --------------------------------------------------
  17. // CONSOLE
  18. <1> <<indices-create-index,Creates an index>> called `twitter` without any mapping.
  19. <2> Uses the PUT mapping API to add a new field called `email`.
  20. More information on how to define mappings can be found in the <<mapping,mapping>> section.
  21. NOTE: Before 7.0.0, the 'mappings' definition used to include a type name. Although specifying
  22. types in requests is now deprecated, a type can still be provided if the request parameter
  23. include_type_name is set. For more details, please see <<removal-of-types>>.
  24. [float]
  25. === Multi-index
  26. The PUT mapping API can be applied to multiple indices with a single request.
  27. For example, we can update the `twitter-1` and `twitter-2` mappings at the same time:
  28. [source,js]
  29. --------------------------------------------------
  30. # Create the two indices
  31. PUT twitter-1
  32. PUT twitter-2
  33. # Update both mappings
  34. PUT /twitter-1,twitter-2/_mapping <1>
  35. {
  36. "properties": {
  37. "user_name": {
  38. "type": "text"
  39. }
  40. }
  41. }
  42. --------------------------------------------------
  43. // CONSOLE
  44. <1> Note that the indices specified (`twitter-1,twitter-2`) follows <<multi-index,multiple index names>> and wildcard format.
  45. [[updating-field-mappings]]
  46. [float]
  47. === Updating field mappings
  48. In general, the mapping for existing fields cannot be updated. There are some
  49. exceptions to this rule. For instance:
  50. * new <<properties>> can be added to <<object>> fields.
  51. * new <<multi-fields,multi-fields>> can be added to existing fields.
  52. * the <<ignore-above>> parameter can be updated.
  53. For example:
  54. [source,js]
  55. -----------------------------------
  56. PUT my_index <1>
  57. {
  58. "mappings": {
  59. "properties": {
  60. "name": {
  61. "properties": {
  62. "first": {
  63. "type": "text"
  64. }
  65. }
  66. },
  67. "user_id": {
  68. "type": "keyword"
  69. }
  70. }
  71. }
  72. }
  73. PUT my_index/_mapping
  74. {
  75. "properties": {
  76. "name": {
  77. "properties": {
  78. "last": { <2>
  79. "type": "text"
  80. }
  81. }
  82. },
  83. "user_id": {
  84. "type": "keyword",
  85. "ignore_above": 100 <3>
  86. }
  87. }
  88. }
  89. -----------------------------------
  90. // CONSOLE
  91. <1> Create an index with a `first` field under the `name` <<object>> field, and a `user_id` field.
  92. <2> Add a `last` field under the `name` object field.
  93. <3> Update the `ignore_above` setting from its default of 0.
  94. Each <<mapping-params,mapping parameter>> specifies whether or not its setting
  95. can be updated on an existing field.