[[indices-put-mapping]]
=== Put mapping API
++++
Put mapping
++++
Adds new fields to an existing data stream or index. You can also use the
put mapping 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 /twitter/_mapping
{
"properties": {
"email": {
"type": "keyword"
}
}
}
----
// TEST[setup:twitter]
NOTE: Before 7.0.0, the 'mappings' definition used to include a type name.
Although specifying types in requests is now deprecated, a type can still be
provided if the request parameter `include_type_name` is set. For more details,
please see <>.
[[put-mapping-api-request]]
==== {api-request-title}
`PUT //_mapping`
`PUT /_mapping`
[[put-mapping-api-path-params]]
==== {api-path-parms-title}
``::
(Optional, string)
Comma-separated list of data streams, indices, and index aliases used to limit
the request. Wildcard expressions (`*`) are supported.
+
To target all data streams and indices in a cluster, omit this parameter or use
`_all` or `*`.
[[put-mapping-api-query-params]]
==== {api-query-parms-title}
include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=allow-no-indices]
+
Defaults to `false`.
include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=expand-wildcards]
+
Defaults to `open`.
include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=include-type-name]
include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=index-ignore-unavailable]
include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=timeoutparms]
[[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 put 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 put 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 PUT mapping API can be applied to multiple data streams or indices with a single request.
For example, you can update mappings for the `twitter-1` and `twitter-2` indices at the same time:
[source,console]
--------------------------------------------------
# Create the two indices
PUT /twitter-1
PUT /twitter-2
# Update both mappings
PUT /twitter-1,twitter-2/_mapping <1>
{
"properties": {
"user_name": {
"type": "text"
}
}
}
--------------------------------------------------
// TEST[setup:twitter]
<1> Note that the indices specified (`twitter-1,twitter-2`) follows <> and wildcard format.
[[add-new-field-to-object]]
===== Add new properties to an existing object field
You can use the put mapping API
to add new properties
to an existing <