123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- [[java-rest-high-put-mapping]]
- === Put Mapping API
- [[java-rest-high-put-mapping-request]]
- ==== Put Mapping Request
- A `PutMappingRequest` requires an `index` argument, and a type:
- ["source","java",subs="attributes,callouts,macros"]
- --------------------------------------------------
- include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[put-mapping-request]
- --------------------------------------------------
- <1> The index to add the mapping to
- <2> The type to create (or update)
- ==== Mapping source
- A description of the fields to create on the mapping; if not defined, the mapping will default to empty.
- ["source","java",subs="attributes,callouts,macros"]
- --------------------------------------------------
- include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[put-mapping-request-source]
- --------------------------------------------------
- <1> Mapping source provided as a `String`
- ==== Providing the mapping source
- The mapping source can be provided in different ways in addition to
- the `String` example shown above:
- ["source","java",subs="attributes,callouts,macros"]
- --------------------------------------------------
- include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[put-mapping-map]
- --------------------------------------------------
- <1> Mapping source provided as a `Map` which gets automatically converted
- to JSON format
- ["source","java",subs="attributes,callouts,macros"]
- --------------------------------------------------
- include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[put-mapping-xcontent]
- --------------------------------------------------
- <1> Mapping source provided as an `XContentBuilder` object, the Elasticsearch
- built-in helpers to generate JSON content
- ["source","java",subs="attributes,callouts,macros"]
- --------------------------------------------------
- include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[put-mapping-shortcut]
- --------------------------------------------------
- <1> Mapping source provided as `Object` key-pairs, which gets converted to
- JSON format
- ==== Optional arguments
- The following arguments can optionally be provided:
- ["source","java",subs="attributes,callouts,macros"]
- --------------------------------------------------
- include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[put-mapping-request-timeout]
- --------------------------------------------------
- <1> Timeout to wait for the all the nodes to acknowledge the index creation as a `TimeValue`
- <2> Timeout to wait for the all the nodes to acknowledge the index creation as a `String`
- ["source","java",subs="attributes,callouts,macros"]
- --------------------------------------------------
- include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[put-mapping-request-masterTimeout]
- --------------------------------------------------
- <1> Timeout to connect to the master node as a `TimeValue`
- <2> Timeout to connect to the master node as a `String`
- [[java-rest-high-put-mapping-sync]]
- ==== Synchronous Execution
- ["source","java",subs="attributes,callouts,macros"]
- --------------------------------------------------
- include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[put-mapping-execute]
- --------------------------------------------------
- [[java-rest-high-put-mapping-async]]
- ==== Asynchronous Execution
- The asynchronous execution of a put mappings request requires both the `PutMappingRequest`
- instance and an `ActionListener` instance to be passed to the asynchronous
- method:
- ["source","java",subs="attributes,callouts,macros"]
- --------------------------------------------------
- include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[put-mapping-execute-async]
- --------------------------------------------------
- <1> The `PutMappingRequest` to execute and the `ActionListener` to use when
- the execution completes
- The asynchronous method does not block and returns immediately. Once it is
- completed the `ActionListener` is called back using the `onResponse` method
- if the execution successfully completed or using the `onFailure` method if
- it failed.
- A typical listener for `PutMappingResponse` looks like:
- ["source","java",subs="attributes,callouts,macros"]
- --------------------------------------------------
- include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[put-mapping-execute-listener]
- --------------------------------------------------
- <1> Called when the execution is successfully completed. The response is
- provided as an argument
- <2> Called in case of failure. The raised exception is provided as an argument
- [[java-rest-high-put-mapping-response]]
- ==== Put Mapping Response
- The returned `PutMappingResponse` allows to retrieve information about the executed
- operation as follows:
- ["source","java",subs="attributes,callouts,macros"]
- --------------------------------------------------
- include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[put-mapping-response]
- --------------------------------------------------
- <1> Indicates whether all of the nodes have acknowledged the request
|