OpenSearch/docs/java-api/admin/indices/put-mapping.asciidoc

31 lines
1.3 KiB
Plaintext

[[java-admin-indices-put-mapping]]
==== Put Mapping
You can add mappings at index creation time:
["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{client-tests}/IndicesDocumentationIT.java[index-with-mapping]
--------------------------------------------------
<1> <<java-admin-indices-create-index,Creates an index>> called `twitter`
<2> Add a `_doc` type with a field called `message` that has the data type `text`.
There are several variants of the above `addMapping` method, some taking an
`XContentBuilder` or a `Map` with the mapping definition as arguments. Make sure
to check the javadocs to pick the simplest one for your use case.
The PUT mapping API also allows for updating the mapping after index
creation. In this case you can provide the mapping as a String similar
to the REST API syntax:
["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{client-tests}/IndicesDocumentationIT.java[putMapping-request-source]
--------------------------------------------------
<1> Puts a mapping on existing index called `twitter`
<2> Adds a new field `name` to the mapping
<3> The type can be also provided within the source
:base-dir!: