| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 | [[java-rest-high-create-index]]=== Create Index API[[java-rest-high-create-index-request]]==== Create Index RequestA `CreateIndexRequest` requires an `index` argument:["source","java",subs="attributes,callouts,macros"]--------------------------------------------------include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[create-index-request]--------------------------------------------------<1> The index to create==== Index settingsEach index created can have specific settings associated with it.["source","java",subs="attributes,callouts,macros"]--------------------------------------------------include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[create-index-request-settings]--------------------------------------------------<1> Settings for this index[[java-rest-high-create-index-request-mappings]]==== Index mappingsAn index may be created with mappings for its document types["source","java",subs="attributes,callouts,macros"]--------------------------------------------------include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[create-index-request-mappings]--------------------------------------------------<1> The type to define<2> The mapping for this type, provided as a JSON stringThe 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[create-index-mappings-map]--------------------------------------------------<1> Mapping source provided as a `Map` which gets automatically convertedto JSON format["source","java",subs="attributes,callouts,macros"]--------------------------------------------------include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[create-index-mappings-xcontent]--------------------------------------------------<1> Mapping source provided as an `XContentBuilder` object, the Elasticsearchbuilt-in helpers to generate JSON content["source","java",subs="attributes,callouts,macros"]--------------------------------------------------include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[create-index-mappings-shortcut]--------------------------------------------------<1> Mapping source provided as `Object` key-pairs, which gets converted toJSON format==== Index aliasesAliases can be set at index creation time["source","java",subs="attributes,callouts,macros"]--------------------------------------------------include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[create-index-request-aliases]--------------------------------------------------<1> The alias to define==== Providing the whole sourceThe whole source including all of its sections (mappings, settings and aliases)can also be provided:["source","java",subs="attributes,callouts,macros"]--------------------------------------------------include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[create-index-whole-source]--------------------------------------------------<1> The source provided as a JSON string. It can also be provided as a `Map`or an `XContentBuilder`.==== Optional argumentsThe following arguments can optionally be provided:["source","java",subs="attributes,callouts,macros"]--------------------------------------------------include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[create-index-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[create-index-request-masterTimeout]--------------------------------------------------<1> Timeout to connect to the master node as a `TimeValue`<2> Timeout to connect to the master node as a `String`["source","java",subs="attributes,callouts,macros"]--------------------------------------------------include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[create-index-request-waitForActiveShards]--------------------------------------------------<1> The number of active shard copies to wait for before the create index API returns aresponse, as an `int`<2> The number of active shard copies to wait for before the create index API returns aresponse, as an `ActiveShardCount`[[java-rest-high-create-index-sync]]==== Synchronous Execution["source","java",subs="attributes,callouts,macros"]--------------------------------------------------include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[create-index-execute]--------------------------------------------------[[java-rest-high-create-index-async]]==== Asynchronous ExecutionThe asynchronous execution of a create index request requires both the `CreateIndexRequest`instance and an `ActionListener` instance to be passed to the asynchronousmethod:["source","java",subs="attributes,callouts,macros"]--------------------------------------------------include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[create-index-execute-async]--------------------------------------------------<1> The `CreateIndexRequest` to execute and the `ActionListener` to use whenthe execution completesThe asynchronous method does not block and returns immediately. Once it iscompleted the `ActionListener` is called back using the `onResponse` methodif the execution successfully completed or using the `onFailure` method ifit failed.A typical listener for `CreateIndexResponse` looks like:["source","java",subs="attributes,callouts,macros"]--------------------------------------------------include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[create-index-execute-listener]--------------------------------------------------<1> Called when the execution is successfully completed. The response isprovided as an argument<2> Called in case of failure. The raised exception is provided as an argument[[java-rest-high-create-index-response]]==== Create Index ResponseThe returned `CreateIndexResponse` allows to retrieve information about the executed operation as follows:["source","java",subs="attributes,callouts,macros"]--------------------------------------------------include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[create-index-response]--------------------------------------------------<1> Indicates whether all of the nodes have acknowledged the request<2> Indicates whether the requisite number of shard copies were started for each shard in the index before timing out
 |