| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 | --:api: index:request: IndexRequest:response: IndexResponse--[id="{upid}-{api}"]=== Index API[id="{upid}-{api}-request"]==== Index RequestAn +{request}+ requires the following arguments:["source","java",subs="attributes,callouts,macros"]--------------------------------------------------include-tagged::{doc-tests-file}[{api}-request-string]--------------------------------------------------<1> Index<2> Type<3> Document id<4> Document source provided as a `String`==== Providing the document sourceThe document 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-file}[{api}-request-map]--------------------------------------------------<1> Document source provided as a `Map` which gets automatically convertedto JSON format["source","java",subs="attributes,callouts,macros"]--------------------------------------------------include-tagged::{doc-tests-file}[{api}-request-xcontent]--------------------------------------------------<1> Document source provided as an `XContentBuilder` object, the Elasticsearchbuilt-in helpers to generate JSON content["source","java",subs="attributes,callouts,macros"]--------------------------------------------------include-tagged::{doc-tests-file}[{api}-request-shortcut]--------------------------------------------------<1> Document source provided as `Object` key-pairs, which gets converted toJSON format==== Optional argumentsThe following arguments can optionally be provided:["source","java",subs="attributes,callouts,macros"]--------------------------------------------------include-tagged::{doc-tests-file}[{api}-request-routing]--------------------------------------------------<1> Routing value["source","java",subs="attributes,callouts,macros"]--------------------------------------------------include-tagged::{doc-tests-file}[{api}-request-timeout]--------------------------------------------------<1> Timeout to wait for primary shard to become available as a `TimeValue`<2> Timeout to wait for primary shard to become available as a `String`["source","java",subs="attributes,callouts,macros"]--------------------------------------------------include-tagged::{doc-tests-file}[{api}-request-refresh]--------------------------------------------------<1> Refresh policy as a `WriteRequest.RefreshPolicy` instance<2> Refresh policy as a `String`["source","java",subs="attributes,callouts,macros"]--------------------------------------------------include-tagged::{doc-tests-file}[{api}-request-version]--------------------------------------------------<1> Version["source","java",subs="attributes,callouts,macros"]--------------------------------------------------include-tagged::{doc-tests-file}[{api}-request-version-type]--------------------------------------------------<1> Version type["source","java",subs="attributes,callouts,macros"]--------------------------------------------------include-tagged::{doc-tests-file}[{api}-request-op-type]--------------------------------------------------<1> Operation type provided as an `DocWriteRequest.OpType` value<2> Operation type provided as a `String`: can be `create` or `update` (default)["source","java",subs="attributes,callouts,macros"]--------------------------------------------------include-tagged::{doc-tests-file}[{api}-request-pipeline]--------------------------------------------------<1> The name of the ingest pipeline to be executed before indexing the documentinclude::../execution.asciidoc[][id="{upid}-{api}-response"]==== Index ResponseThe returned +{response}+ allows to retrieve information about the executed operation as follows:["source","java",subs="attributes,callouts,macros"]--------------------------------------------------include-tagged::{doc-tests-file}[{api}-response]--------------------------------------------------<1> Handle (if needed) the case where the document was created for the firsttime<2> Handle (if needed) the case where the document was rewritten as it wasalready existing<3> Handle the situation where number of successful shards is less thantotal shards<4> Handle the potential failuresIf there is a version conflict, an `ElasticsearchException` willbe thrown:["source","java",subs="attributes,callouts,macros"]--------------------------------------------------include-tagged::{doc-tests-file}[{api}-conflict]--------------------------------------------------<1> The raised exception indicates that a version conflict error was returnedSame will happen in case `opType` was set to `create` and a document withsame index, type and id already existed:["source","java",subs="attributes,callouts,macros"]--------------------------------------------------include-tagged::{doc-tests-file}[{api}-optype]--------------------------------------------------<1> The raised exception indicates that a version conflict error was returned
 |