create_index.asciidoc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. [[java-rest-high-create-index]]
  2. === Create Index API
  3. [[java-rest-high-create-index-request]]
  4. ==== Create Index Request
  5. A `CreateIndexRequest` requires an `index` argument:
  6. ["source","java",subs="attributes,callouts,macros"]
  7. --------------------------------------------------
  8. include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[create-index-request]
  9. --------------------------------------------------
  10. <1> The index to create
  11. ==== Index settings
  12. Each index created can have specific settings associated with it.
  13. ["source","java",subs="attributes,callouts,macros"]
  14. --------------------------------------------------
  15. include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[create-index-request-settings]
  16. --------------------------------------------------
  17. <1> Settings for this index
  18. ==== Index mappings
  19. An index may be created with mappings for its document types
  20. ["source","java",subs="attributes,callouts,macros"]
  21. --------------------------------------------------
  22. include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[create-index-request-mappings]
  23. --------------------------------------------------
  24. <1> The type to define
  25. <2> The mapping for this type, provided as a JSON string
  26. ==== Index aliases
  27. Aliases can be set at index creation time
  28. ["source","java",subs="attributes,callouts,macros"]
  29. --------------------------------------------------
  30. include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[create-index-request-aliases]
  31. --------------------------------------------------
  32. <1> The alias to define
  33. ==== Optional arguments
  34. The following arguments can optionally be provided:
  35. ["source","java",subs="attributes,callouts,macros"]
  36. --------------------------------------------------
  37. include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[create-index-request-timeout]
  38. --------------------------------------------------
  39. <1> Timeout to wait for the all the nodes to acknowledge the index creation as a `TimeValue`
  40. <2> Timeout to wait for the all the nodes to acknowledge the index creation as a `String`
  41. ["source","java",subs="attributes,callouts,macros"]
  42. --------------------------------------------------
  43. include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[create-index-request-masterTimeout]
  44. --------------------------------------------------
  45. <1> Timeout to connect to the master node as a `TimeValue`
  46. <2> Timeout to connect to the master node as a `String`
  47. ["source","java",subs="attributes,callouts,macros"]
  48. --------------------------------------------------
  49. include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[create-index-request-waitForActiveShards]
  50. --------------------------------------------------
  51. <1> The number of active shard copies to wait for before the create index API returns a
  52. response, as an `int`.
  53. <2> The number of active shard copies to wait for before the create index API returns a
  54. response, as an `ActiveShardCount`.
  55. [[java-rest-high-create-index-sync]]
  56. ==== Synchronous Execution
  57. ["source","java",subs="attributes,callouts,macros"]
  58. --------------------------------------------------
  59. include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[create-index-execute]
  60. --------------------------------------------------
  61. [[java-rest-high-create-index-async]]
  62. ==== Asynchronous Execution
  63. The asynchronous execution of a create index request requires both the `CreateIndexRequest`
  64. instance and an `ActionListener` instance to be passed to the asynchronous
  65. method:
  66. ["source","java",subs="attributes,callouts,macros"]
  67. --------------------------------------------------
  68. include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[create-index-execute-async]
  69. --------------------------------------------------
  70. <1> The `CreateIndexRequest` to execute and the `ActionListener` to use when
  71. the execution completes
  72. The asynchronous method does not block and returns immediately. Once it is
  73. completed the `ActionListener` is called back using the `onResponse` method
  74. if the execution successfully completed or using the `onFailure` method if
  75. it failed.
  76. A typical listener for `CreateIndexResponse` looks like:
  77. ["source","java",subs="attributes,callouts,macros"]
  78. --------------------------------------------------
  79. include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[create-index-execute-listener]
  80. --------------------------------------------------
  81. <1> Called when the execution is successfully completed. The response is
  82. provided as an argument
  83. <2> Called in case of failure. The raised exception is provided as an argument
  84. [[java-rest-high-create-index-response]]
  85. ==== Create Index Response
  86. The returned `CreateIndexResponse` allows to retrieve information about the executed
  87. operation as follows:
  88. ["source","java",subs="attributes,callouts,macros"]
  89. --------------------------------------------------
  90. include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[create-index-response]
  91. --------------------------------------------------
  92. <1> Indicates whether all of the nodes have acknowledged the request
  93. <2> Indicates whether the requisite number of shard copies were started for each shard in the index before timing out