11[[indices-put-mapping]]
2- === Put Mapping
2+ === Put mapping API
3+ ++++
4+ <titleabbrev>Put mapping</titleabbrev>
5+ ++++
36
4- The PUT mapping API allows you to add fields to an existing index or to change search only settings of existing fields.
7+ Adds new fields to an existing index or changes the search settings of existing
8+ fields.
59
610[source,js]
7- --------------------------------------------------
8- PUT twitter <1>
9- {}
10-
11- PUT twitter/_mapping <2>
11+ ----
12+ PUT /twitter/_mapping
1213{
1314 "properties": {
1415 "email": {
1516 "type": "keyword"
1617 }
1718 }
1819}
19- --------------------------------------------------
20+ ----
21+ // CONSOLE
22+ // TEST[setup:twitter]
23+
24+ NOTE: Before 7.0.0, the 'mappings' definition used to include a type name.
25+ Although specifying types in requests is now deprecated, a type can still be
26+ provided if the request parameter `include_type_name` is set. For more details,
27+ please see <<removal-of-types>>.
28+
29+
30+ [[put-mapping-api-request]]
31+ ==== {api-request-title}
32+
33+ `PUT /{index}/_mapping`
34+
35+ `PUT /_mapping`
36+
37+
38+ [[put-mapping-api-path-params]]
39+ ==== {api-path-parms-title}
40+
41+ include::{docdir}/rest-api/common-parms.asciidoc[tag=index]
42+ +
43+ To update the mapping of all indices, omit this parameter or use a value of
44+ `_all`.
45+
46+
47+ [[put-mapping-api-query-params]]
48+ ==== {api-query-parms-title}
49+
50+ include::{docdir}/rest-api/common-parms.asciidoc[tag=allow-no-indices]
51+
52+ include::{docdir}/rest-api/common-parms.asciidoc[tag=expand-wildcards]
53+ +
54+ Defaults to `open`.
55+
56+ include::{docdir}/rest-api/common-parms.asciidoc[tag=include-type-name]
57+
58+ include::{docdir}/rest-api/common-parms.asciidoc[tag=index-ignore-unavailable]
59+
60+ include::{docdir}/rest-api/common-parms.asciidoc[tag=timeoutparms]
61+
62+
63+ [[put-mapping-api-request-body]]
64+ ==== {api-request-body-title}
65+
66+ `properties`::
67+ +
68+ --
69+ (Required, <<mapping,mapping object>>) Mapping for a field. For new
70+ fields, this mapping can include:
71+
72+ * Field name
73+ * <<field-datatypes,Field datatype>>
74+ * <<mapping-params,Mapping parameters>>
75+
76+ For existing fields, see <<updating-field-mappings>>.
77+ --
78+
79+
80+ [[put-mapping-api-example]]
81+ ==== {api-examples-title}
82+
83+ [[put-field-mapping-api-basic-ex]]
84+ ===== Example with index setup
85+
86+ The put mapping API requires an existing index. The following
87+ <<indices-create-index, create index>> API request creates the `publications`
88+ index with no mapping.
89+
90+ [source,js]
91+ ----
92+ PUT /publications
93+ ----
2094// CONSOLE
21- <1> <<indices-create-index,Creates an index>> called `twitter` without any mapping.
22- <2> Uses the PUT mapping API to add a new field called `email`.
2395
24- More information on how to define mappings can be found in the <<mapping,mapping>> section.
96+ The following put mapping API request adds `title`, a new <<text,`text`>> field,
97+ to the `publications` index.
2598
26- NOTE: Before 7.0.0, the 'mappings' definition used to include a type name. Although specifying
27- types in requests is now deprecated, a type can still be provided if the request parameter
28- include_type_name is set. For more details, please see <<removal-of-types>>.
99+ [source,js]
100+ ----
101+ PUT /publications/_mapping
102+ {
103+ "properties": {
104+ "title": { "type": "text"}
105+ }
106+ }
107+ ----
108+ // CONSOLE
109+ // TEST[continued]
29110
30- [float ]
31- ==== Multi-index
111+ [[put-mapping-api-multi-ex] ]
112+ ===== Multiple indices
32113
33114The PUT mapping API can be applied to multiple indices with a single request.
34115For example, we can update the `twitter-1` and `twitter-2` mappings at the same time:
35116
36117[source,js]
37118--------------------------------------------------
38119# Create the two indices
39- PUT twitter-1
40- PUT twitter-2
120+ PUT / twitter-1
121+ PUT / twitter-2
41122
42123# Update both mappings
43124PUT /twitter-1,twitter-2/_mapping <1>
@@ -50,12 +131,12 @@ PUT /twitter-1,twitter-2/_mapping <1>
50131}
51132--------------------------------------------------
52133// CONSOLE
53- <1> Note that the indices specified (` twitter-1,twitter-2`) follows <<multi-index,multiple index names>> and wildcard format.
134+ // TEST[setup: twitter]
54135
136+ <1> Note that the indices specified (`twitter-1,twitter-2`) follows <<multi-index,multiple index names>> and wildcard format.
55137
56138[[updating-field-mappings]]
57- [float]
58- ==== Updating field mappings
139+ ===== Update an existing field
59140
60141// tag::put-field-mapping-exceptions[]
61142
@@ -79,7 +160,7 @@ For example:
79160
80161[source,js]
81162-----------------------------------
82- PUT my_index <1>
163+ PUT / my_index <1>
83164{
84165 "mappings": {
85166 "properties": {
@@ -97,7 +178,7 @@ PUT my_index <1>
97178 }
98179}
99180
100- PUT my_index/_mapping
181+ PUT / my_index/_mapping
101182{
102183 "properties": {
103184 "name": {
0 commit comments