@@ -118,49 +118,151 @@ You know more about your data than Elasticsearch can guess, so while dynamic
118
118
mapping can be useful to get started, at some point you will want to specify
119
119
your own explicit mappings.
120
120
121
- You can create field mappings when you
122
- <<indices-create-index,create an index>>, and you can add
123
- fields to an existing index with the <<indices-put-mapping,PUT mapping API>>.
121
+ You can create field mappings when you <<create-mapping,create an index>> and
122
+ <<add-field-mapping,add fields to an existing index>>.
124
123
125
124
[float]
126
- == Updating existing field mappings
125
+ [[create-mapping]]
126
+ == Create an index with an explicit mapping
127
127
128
- Other than where documented, *existing field mappings cannot be
129
- updated*. Changing the mapping would mean invalidating already indexed
130
- documents. Instead, you should create a new index with the correct mappings
131
- and <<docs-reindex,reindex>> your data into that index. If you only wish
132
- to rename a field and not change its mappings, it may make sense to introduce
133
- an <<alias, `alias`>> field.
128
+ You can use the <<indices-create-index,create index>> API to create a new index
129
+ with an explicit mapping.
130
+
131
+ [source,js]
132
+ ----
133
+ PUT /my-index
134
+ {
135
+ "mappings": {
136
+ "properties": {
137
+ "age": { "type": "integer" }, <1>
138
+ "email": { "type": "keyword" }, <2>
139
+ "name": { "type": "text" } <3>
140
+ }
141
+ }
142
+ }
143
+ ----
144
+ // CONSOLE
145
+
146
+ <1> Creates `age`, an <<number,`integer`>> field
147
+ <2> Creates `email`, a <<keyword,`keyword`>> field
148
+ <3> Creates `name`, a <<text,`text`>> field
134
149
135
150
[float]
136
- == Example mapping
151
+ [[add-field-mapping]]
152
+ == Add a field to an existing mapping
137
153
138
- A mapping can be specified when creating an index, as follows:
154
+ You can use the <<indices-put-mapping, put mapping>> API to add one or more new
155
+ fields to an existing index.
156
+
157
+ The following example adds `employee-id`, a `keyword` field with an
158
+ <<mapping-index,`index`>> mapping parameter value of `false`. This means values
159
+ for the `employee-id` field are stored but not indexed or available for search.
139
160
140
161
[source,js]
141
- ---------------------------------------
142
- PUT my_index <1>
162
+ ----
163
+ PUT /my-index/_mapping
143
164
{
144
- "mappings": {
145
- "properties": { <2>
146
- "title": { "type": "text" }, <3>
147
- "name": { "type": "text" }, <4>
148
- "age": { "type": "integer" }, <5>
149
- "created": {
150
- "type": "date", <6>
151
- "format": "strict_date_optional_time||epoch_millis"
165
+ "properties": {
166
+ "employee-id": {
167
+ "type": "keyword",
168
+ "index": false
169
+ }
170
+ }
171
+ }
172
+ ----
173
+ // CONSOLE
174
+ // TEST[continued]
175
+
176
+ [float]
177
+ [[update-mapping]]
178
+ === Update the mapping of a field
179
+
180
+ include::{docdir}/indices/put-mapping.asciidoc[tag=put-field-mapping-exceptions]
181
+
182
+ [float]
183
+ [[view-mapping]]
184
+ == View the mapping of an index
185
+
186
+ You can use the <<indices-get-mapping, get mapping>> API to view the mapping of
187
+ an existing index.
188
+
189
+ [source,js]
190
+ ----
191
+ GET /my-index/_mapping
192
+ ----
193
+ // CONSOLE
194
+ // TEST[continued]
195
+
196
+ The API returns the following response:
197
+
198
+ [source,js]
199
+ ----
200
+ {
201
+ "my-index" : {
202
+ "mappings" : {
203
+ "properties" : {
204
+ "age" : {
205
+ "type" : "integer"
206
+ },
207
+ "email" : {
208
+ "type" : "keyword"
209
+ },
210
+ "employee-id" : {
211
+ "type" : "keyword",
212
+ "index" : false
213
+ },
214
+ "name" : {
215
+ "type" : "text"
216
+ }
152
217
}
153
218
}
154
219
}
155
220
}
156
- ---------------------------------------
221
+ ----
222
+ // TESTRESPONSE
223
+
224
+
225
+ [float]
226
+ [[view-field-mapping]]
227
+ == View the mapping of specific fields
228
+
229
+ If you only want to view the mapping of one or more specific fields, you can use
230
+ the <<indices-get-field-mapping, get field mapping>> API.
231
+
232
+ This is useful if you don't need the complete mapping of an index or your index
233
+ contains a large number of fields.
234
+
235
+ The following request retrieves the mapping for the `employee-id` field.
236
+
237
+ [source,js]
238
+ ----
239
+ GET /my-index/_mapping/field/employee-id
240
+ ----
157
241
// CONSOLE
158
- <1> Create an index called `my_index`.
159
- <2> Specify the fields or _properties_ in the mapping.
160
- <3> Specify that the `title` field contains `text` values.
161
- <4> Specify that the `name` field contains `text` values.
162
- <5> Specify that the `age` field contains `integer` values.
163
- <6> Specify that the `created` field contains `date` values in two possible formats.
242
+ // TEST[continued]
243
+
244
+ The API returns the following response:
245
+
246
+ [source,js]
247
+ ----
248
+ {
249
+ "my-index" : {
250
+ "mappings" : {
251
+ "employee-id" : {
252
+ "full_name" : "employee-id",
253
+ "mapping" : {
254
+ "employee-id" : {
255
+ "type" : "keyword",
256
+ "index" : false
257
+ }
258
+ }
259
+ }
260
+ }
261
+ }
262
+ }
263
+
264
+ ----
265
+ // TESTRESPONSE
164
266
165
267
--
166
268
0 commit comments