[[java-admin-indices-put-mapping]]
:base-dir: {docdir}/../../server/src/test/java/org/elasticsearch/action/admin/indices/create

==== Put Mapping

The PUT mapping API allows you to add a new type while creating an index:

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{base-dir}/CreateIndexIT.java[addMapping-create-index-request]
--------------------------------------------------
<1> <<java-admin-indices-create-index,Creates an index>> called `twitter`
<2> It also adds a `tweet` mapping type.


The PUT mapping API also allows to add a new type to an existing index:

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{base-dir}/CreateIndexIT.java[putMapping-request-source]
--------------------------------------------------
<1> Puts a mapping on existing index called `twitter`
<2> Adds a `user` mapping type.
<3> This `user` has a predefined type
<4> type can be also provided within the source

You can use the same API to update an existing mapping:

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{base-dir}/CreateIndexIT.java[putMapping-request-source-append]
--------------------------------------------------
<1> Puts a mapping on existing index called `twitter`
<2> Updates the `user` mapping type.
<3> This `user` has now a new field `user_name`

:base-dir!:

[[java-admin-indices-put-mapping]]
:base-dir: {docdir}/../../core/src/test/java/org/elasticsearch/action/admin/indices/create

==== Put Mapping

The PUT mapping API allows you to add a new type while creating an index:

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{base-dir}/CreateIndexIT.java[addMapping-create-index-request]
--------------------------------------------------
<1> <<java-admin-indices-create-index,Creates an index>> called `twitter`
<2> It also adds a `tweet` mapping type.


The PUT mapping API also allows to add a new type to an existing index:

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{base-dir}/CreateIndexIT.java[putMapping-request-source]
--------------------------------------------------
<1> Puts a mapping on existing index called `twitter`
<2> Adds a `user` mapping type.
<3> This `user` has a predefined type
<4> type can be also provided within the source

You can use the same API to update an existing mapping:

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{base-dir}/CreateIndexIT.java[putMapping-request-source-append]
--------------------------------------------------
<1> Puts a mapping on existing index called `twitter`
<2> Updates the `user` mapping type.
<3> This `user` has now a new field `user_name`

:base-dir!:
Revert "[Docs] Fix base directory to include for put_mapping.asciidoc"
Revert "[Docs] Fix base directory to include for put_mapping.asciidoc"

This reverts commit 4f5be7db3ce9f1ea7f864cc1fd38ee09363aa64d.
