[[indices-put-mapping]]
=== Update mapping API
++++
Update mapping
++++
Adds new fields to an existing data stream or index. You can also use this
API to change the search settings of existing fields.
For data streams, these changes are applied to all backing indices by default.
[source,console]
----
PUT /my-index-000001/_mapping
{
"properties": {
"email": {
"type": "keyword"
}
}
}
----
// TEST[setup:my_index]
[[put-mapping-api-request]]
==== {api-request-title}
`PUT //_mapping`
[[put-mapping-api-prereqs]]
==== {api-prereq-title}
* If the {es} {security-features} are enabled, you must have the `manage`
<> for the target data stream, index,
or alias.
+
deprecated:[7.9] If the request targets an index or index alias, you can also
update its mapping with the `create`, `create_doc`, `index`, or `write` index
privilege.
[[put-mapping-api-path-params]]
==== {api-path-parms-title}
``::
(Required, string) Comma-separated list of data streams, indices, and aliases
used to limit the request. Supports wildcards (`*`). To target all data streams
and indices, omit this parameter or use `*` or `_all`.
[[put-mapping-api-query-params]]
==== {api-query-parms-title}
include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=allow-no-indices]
+
Defaults to `false`.
include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=expand-wildcards]
+
Defaults to `open`.
include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=index-ignore-unavailable]
include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=timeoutparms]
`write_index_only`::
(Optional, Boolean)
If `true`,
the mappings are applied only to the current write index for the target.
Defaults to `false`.
[[put-mapping-api-request-body]]
==== {api-request-body-title}
`properties`::
+
--
(Required, <>) Mapping for a field. For new
fields, this mapping can include:
* Field name
* <>
* <>
For existing fields, see <>.
--
[[put-mapping-api-example]]
==== {api-examples-title}
[[put-field-mapping-api-basic-ex]]
===== Example with single target
The update mapping API requires an existing data stream or index. The following
<> API request creates the `publications`
index with no mapping.
[source,console]
----
PUT /publications
----
The following update mapping API request adds `title`, a new <> field,
to the `publications` index.
[source,console]
----
PUT /publications/_mapping
{
"properties": {
"title": { "type": "text"}
}
}
----
// TEST[continued]
[[put-mapping-api-multi-ex]]
===== Multiple targets
The update mapping API can be applied to multiple data streams or indices with a single request.
For example, you can update mappings for the `my-index-000001` and `my-index-000002` indices at the same time:
[source,console]
--------------------------------------------------
# Create the two indices
PUT /my-index-000001
PUT /my-index-000002
# Update both mappings
PUT /my-index-000001,my-index-000002/_mapping
{
"properties": {
"user": {
"properties": {
"name": {
"type": "keyword"
}
}
}
}
}
--------------------------------------------------
[[add-new-field-to-object]]
===== Add new properties to an existing object field
You can use the update mapping API to add new properties to an existing
<