put_mapping.asciidoc 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. [[java-rest-high-put-mapping]]
  2. === Put Mapping API
  3. [[java-rest-high-put-mapping-request]]
  4. ==== Put Mapping Request
  5. A `PutMappingRequest` requires an `index` argument, and a type:
  6. ["source","java",subs="attributes,callouts,macros"]
  7. --------------------------------------------------
  8. include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[put-mapping-request]
  9. --------------------------------------------------
  10. <1> The index to add the mapping to
  11. <2> The type to create (or update)
  12. ==== Mapping source
  13. A description of the fields to create on the mapping; if not defined, the mapping will default to empty.
  14. ["source","java",subs="attributes,callouts,macros"]
  15. --------------------------------------------------
  16. include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[put-mapping-request-source]
  17. --------------------------------------------------
  18. <1> Mapping source provided as a `String`
  19. ==== Providing the mapping source
  20. The mapping source can be provided in different ways in addition to
  21. the `String` example shown above:
  22. ["source","java",subs="attributes,callouts,macros"]
  23. --------------------------------------------------
  24. include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[put-mapping-map]
  25. --------------------------------------------------
  26. <1> Mapping source provided as a `Map` which gets automatically converted
  27. to JSON format
  28. ["source","java",subs="attributes,callouts,macros"]
  29. --------------------------------------------------
  30. include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[put-mapping-xcontent]
  31. --------------------------------------------------
  32. <1> Mapping source provided as an `XContentBuilder` object, the Elasticsearch
  33. built-in helpers to generate JSON content
  34. ["source","java",subs="attributes,callouts,macros"]
  35. --------------------------------------------------
  36. include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[put-mapping-shortcut]
  37. --------------------------------------------------
  38. <1> Mapping source provided as `Object` key-pairs, which gets converted to
  39. JSON format
  40. ==== Optional arguments
  41. The following arguments can optionally be provided:
  42. ["source","java",subs="attributes,callouts,macros"]
  43. --------------------------------------------------
  44. include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[put-mapping-request-timeout]
  45. --------------------------------------------------
  46. <1> Timeout to wait for the all the nodes to acknowledge the index creation as a `TimeValue`
  47. <2> Timeout to wait for the all the nodes to acknowledge the index creation as a `String`
  48. ["source","java",subs="attributes,callouts,macros"]
  49. --------------------------------------------------
  50. include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[put-mapping-request-masterTimeout]
  51. --------------------------------------------------
  52. <1> Timeout to connect to the master node as a `TimeValue`
  53. <2> Timeout to connect to the master node as a `String`
  54. [[java-rest-high-put-mapping-sync]]
  55. ==== Synchronous Execution
  56. ["source","java",subs="attributes,callouts,macros"]
  57. --------------------------------------------------
  58. include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[put-mapping-execute]
  59. --------------------------------------------------
  60. [[java-rest-high-put-mapping-async]]
  61. ==== Asynchronous Execution
  62. The asynchronous execution of a put mappings request requires both the `PutMappingRequest`
  63. instance and an `ActionListener` instance to be passed to the asynchronous
  64. method:
  65. ["source","java",subs="attributes,callouts,macros"]
  66. --------------------------------------------------
  67. include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[put-mapping-execute-async]
  68. --------------------------------------------------
  69. <1> The `PutMappingRequest` to execute and the `ActionListener` to use when
  70. the execution completes
  71. The asynchronous method does not block and returns immediately. Once it is
  72. completed the `ActionListener` is called back using the `onResponse` method
  73. if the execution successfully completed or using the `onFailure` method if
  74. it failed.
  75. A typical listener for `PutMappingResponse` looks like:
  76. ["source","java",subs="attributes,callouts,macros"]
  77. --------------------------------------------------
  78. include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[put-mapping-execute-listener]
  79. --------------------------------------------------
  80. <1> Called when the execution is successfully completed. The response is
  81. provided as an argument
  82. <2> Called in case of failure. The raised exception is provided as an argument
  83. [[java-rest-high-put-mapping-response]]
  84. ==== Put Mapping Response
  85. The returned `PutMappingResponse` allows to retrieve information about the executed
  86. operation as follows:
  87. ["source","java",subs="attributes,callouts,macros"]
  88. --------------------------------------------------
  89. include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[put-mapping-response]
  90. --------------------------------------------------
  91. <1> Indicates whether all of the nodes have acknowledged the request