2015-12-30 11:50:46 -05:00
|
|
|
[[java-admin-indices-put-mapping]]
|
2018-03-14 17:02:06 -04:00
|
|
|
|
2015-12-30 11:50:46 -05:00
|
|
|
==== Put Mapping
|
|
|
|
|
2018-10-22 14:54:04 -04:00
|
|
|
You can add mappings at index creation time:
|
2015-12-30 11:50:46 -05:00
|
|
|
|
2018-03-01 04:59:52 -05:00
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
2015-12-30 11:50:46 -05:00
|
|
|
--------------------------------------------------
|
2018-03-01 04:59:52 -05:00
|
|
|
include-tagged::{client-tests}/IndicesDocumentationIT.java[index-with-mapping]
|
2015-12-30 11:50:46 -05:00
|
|
|
--------------------------------------------------
|
|
|
|
<1> <<java-admin-indices-create-index,Creates an index>> called `twitter`
|
2018-10-22 14:54:04 -04:00
|
|
|
<2> Add a `_doc` type with a field called `message` that has the datatype `text`.
|
2015-12-30 11:50:46 -05:00
|
|
|
|
2018-07-17 03:09:03 -04:00
|
|
|
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.
|
2015-12-30 11:50:46 -05:00
|
|
|
|
2018-10-22 14:54:04 -04:00
|
|
|
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:
|
2015-12-30 11:50:46 -05:00
|
|
|
|
2018-03-14 17:02:06 -04:00
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
2015-12-30 11:50:46 -05:00
|
|
|
--------------------------------------------------
|
2018-03-14 17:02:06 -04:00
|
|
|
include-tagged::{client-tests}/IndicesDocumentationIT.java[putMapping-request-source]
|
2015-12-30 11:50:46 -05:00
|
|
|
--------------------------------------------------
|
|
|
|
<1> Puts a mapping on existing index called `twitter`
|
2018-10-22 14:54:04 -04:00
|
|
|
<2> Adds a new field `name` to the mapping
|
|
|
|
<3> The type can be also provided within the source
|
2015-12-30 11:50:46 -05:00
|
|
|
|
2018-03-14 17:02:06 -04:00
|
|
|
:base-dir!:
|