create_index.asciidoc 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. --
  2. :api: create-index
  3. :request: CreateIndexRequest
  4. :response: CreateIndexResponse
  5. --
  6. [id="{upid}-{api}"]
  7. === Create Index API
  8. [id="{upid}-{api}-request"]
  9. ==== Create Index Request
  10. A +{request}+ requires an `index` argument:
  11. ["source","java",subs="attributes,callouts,macros"]
  12. --------------------------------------------------
  13. include-tagged::{doc-tests-file}[{api}-request]
  14. --------------------------------------------------
  15. <1> The index to create
  16. ==== Index settings
  17. Each index created can have specific settings associated with it.
  18. ["source","java",subs="attributes,callouts,macros"]
  19. --------------------------------------------------
  20. include-tagged::{doc-tests-file}[{api}-request-settings]
  21. --------------------------------------------------
  22. <1> Settings for this index
  23. [[java-rest-high-create-index-request-mappings]]
  24. ==== Index mappings
  25. An index may be created with mappings for its document types
  26. ["source","java",subs="attributes,callouts,macros"]
  27. --------------------------------------------------
  28. include-tagged::{doc-tests-file}[{api}-request-mappings]
  29. --------------------------------------------------
  30. <1> The type to define
  31. <2> The mapping for this type, provided as a JSON string
  32. The mapping source can be provided in different ways in addition to the
  33. `String` example shown above:
  34. ["source","java",subs="attributes,callouts,macros"]
  35. --------------------------------------------------
  36. include-tagged::{doc-tests-file}[{api}-mappings-map]
  37. --------------------------------------------------
  38. <1> Mapping source provided as a `Map` which gets automatically converted
  39. to JSON format
  40. ["source","java",subs="attributes,callouts,macros"]
  41. --------------------------------------------------
  42. include-tagged::{doc-tests-file}[{api}-mappings-xcontent]
  43. --------------------------------------------------
  44. <1> Mapping source provided as an `XContentBuilder` object, the Elasticsearch
  45. built-in helpers to generate JSON content
  46. ==== Index aliases
  47. Aliases can be set at index creation time
  48. ["source","java",subs="attributes,callouts,macros"]
  49. --------------------------------------------------
  50. include-tagged::{doc-tests-file}[{api}-request-aliases]
  51. --------------------------------------------------
  52. <1> The alias to define
  53. ==== Providing the whole source
  54. The whole source including all of its sections (mappings, settings and aliases)
  55. can also be provided:
  56. ["source","java",subs="attributes,callouts,macros"]
  57. --------------------------------------------------
  58. include-tagged::{doc-tests-file}[{api}-whole-source]
  59. --------------------------------------------------
  60. <1> The source provided as a JSON string. It can also be provided as a `Map`
  61. or an `XContentBuilder`.
  62. ==== Optional arguments
  63. The following arguments can optionally be provided:
  64. ["source","java",subs="attributes,callouts,macros"]
  65. --------------------------------------------------
  66. include-tagged::{doc-tests-file}[{api}-request-timeout]
  67. --------------------------------------------------
  68. <1> Timeout to wait for the all the nodes to acknowledge the index creation as a `TimeValue`
  69. <2> Timeout to wait for the all the nodes to acknowledge the index creation as a `String`
  70. ["source","java",subs="attributes,callouts,macros"]
  71. --------------------------------------------------
  72. include-tagged::{doc-tests-file}[{api}-request-masterTimeout]
  73. --------------------------------------------------
  74. <1> Timeout to connect to the master node as a `TimeValue`
  75. <2> Timeout to connect to the master node as a `String`
  76. ["source","java",subs="attributes,callouts,macros"]
  77. --------------------------------------------------
  78. include-tagged::{doc-tests-file}[{api}-request-waitForActiveShards]
  79. --------------------------------------------------
  80. <1> The number of active shard copies to wait for before the create index API returns a
  81. response, as an `int`
  82. <2> The number of active shard copies to wait for before the create index API returns a
  83. response, as an `ActiveShardCount`
  84. include::../execution.asciidoc[]
  85. [id="{upid}-{api}-response"]
  86. ==== Create Index Response
  87. The returned +{response}+ allows to retrieve information about the executed
  88. operation as follows:
  89. ["source","java",subs="attributes,callouts,macros"]
  90. --------------------------------------------------
  91. include-tagged::{doc-tests-file}[{api}-response]
  92. --------------------------------------------------
  93. <1> Indicates whether all of the nodes have acknowledged the request
  94. <2> Indicates whether the requisite number of shard copies were started for each shard in the index before timing out