2018-10-01 09:59:36 -04:00
|
|
|
--
|
|
|
|
:api: index
|
|
|
|
:request: IndexRequest
|
|
|
|
:response: IndexResponse
|
|
|
|
--
|
|
|
|
|
|
|
|
[id="{upid}-{api}"]
|
2017-07-04 04:58:57 -04:00
|
|
|
=== Index API
|
2017-07-03 04:48:16 -04:00
|
|
|
|
2018-10-01 09:59:36 -04:00
|
|
|
[id="{upid}-{api}-request"]
|
2017-07-04 04:58:57 -04:00
|
|
|
==== Index Request
|
2017-07-03 04:48:16 -04:00
|
|
|
|
2018-10-01 09:59:36 -04:00
|
|
|
An +{request}+ requires the following arguments:
|
2017-07-03 04:48:16 -04:00
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
2018-10-01 09:59:36 -04:00
|
|
|
include-tagged::{doc-tests-file}[{api}-request-string]
|
2017-07-03 04:48:16 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<1> Index
|
2018-12-18 08:53:49 -05:00
|
|
|
<2> Document id for the request
|
|
|
|
<3> Document source provided as a `String`
|
2017-07-03 04:48:16 -04:00
|
|
|
|
2017-07-04 04:58:57 -04:00
|
|
|
==== Providing the document source
|
2018-02-02 04:32:24 -05:00
|
|
|
The document source can be provided in different ways in addition to the
|
|
|
|
`String` example shown above:
|
2017-07-03 04:48:16 -04:00
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
2018-10-01 09:59:36 -04:00
|
|
|
include-tagged::{doc-tests-file}[{api}-request-map]
|
2017-07-03 04:48:16 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<1> Document source provided as a `Map` which gets automatically converted
|
|
|
|
to JSON format
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
2018-10-01 09:59:36 -04:00
|
|
|
include-tagged::{doc-tests-file}[{api}-request-xcontent]
|
2017-07-03 04:48:16 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<1> Document source provided as an `XContentBuilder` object, the Elasticsearch
|
|
|
|
built-in helpers to generate JSON content
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
2018-10-01 09:59:36 -04:00
|
|
|
include-tagged::{doc-tests-file}[{api}-request-shortcut]
|
2017-07-03 04:48:16 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<1> Document source provided as `Object` key-pairs, which gets converted to
|
|
|
|
JSON format
|
|
|
|
|
2017-07-04 04:58:57 -04:00
|
|
|
==== Optional arguments
|
2017-07-03 04:48:16 -04:00
|
|
|
The following arguments can optionally be provided:
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
2018-10-01 09:59:36 -04:00
|
|
|
include-tagged::{doc-tests-file}[{api}-request-routing]
|
2017-07-03 04:48:16 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<1> Routing value
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
2018-10-01 09:59:36 -04:00
|
|
|
include-tagged::{doc-tests-file}[{api}-request-timeout]
|
2017-07-03 04:48:16 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<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"]
|
|
|
|
--------------------------------------------------
|
2018-10-01 09:59:36 -04:00
|
|
|
include-tagged::{doc-tests-file}[{api}-request-refresh]
|
2017-07-03 04:48:16 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<1> Refresh policy as a `WriteRequest.RefreshPolicy` instance
|
|
|
|
<2> Refresh policy as a `String`
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
2018-10-01 09:59:36 -04:00
|
|
|
include-tagged::{doc-tests-file}[{api}-request-version]
|
2017-07-03 04:48:16 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<1> Version
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
2018-10-01 09:59:36 -04:00
|
|
|
include-tagged::{doc-tests-file}[{api}-request-version-type]
|
2017-07-03 04:48:16 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<1> Version type
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
2018-10-01 09:59:36 -04:00
|
|
|
include-tagged::{doc-tests-file}[{api}-request-op-type]
|
2017-07-03 04:48:16 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<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"]
|
|
|
|
--------------------------------------------------
|
2018-10-01 09:59:36 -04:00
|
|
|
include-tagged::{doc-tests-file}[{api}-request-pipeline]
|
2017-07-03 04:48:16 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<1> The name of the ingest pipeline to be executed before indexing the document
|
|
|
|
|
2018-10-01 09:59:36 -04:00
|
|
|
include::../execution.asciidoc[]
|
2017-07-03 04:48:16 -04:00
|
|
|
|
2018-10-01 09:59:36 -04:00
|
|
|
[id="{upid}-{api}-response"]
|
2017-07-04 04:58:57 -04:00
|
|
|
==== Index Response
|
2017-07-03 04:48:16 -04:00
|
|
|
|
2018-10-01 09:59:36 -04:00
|
|
|
The returned +{response}+ allows to retrieve information about the executed
|
2017-07-03 04:48:16 -04:00
|
|
|
operation as follows:
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
2018-10-01 09:59:36 -04:00
|
|
|
include-tagged::{doc-tests-file}[{api}-response]
|
2017-07-03 04:48:16 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<1> Handle (if needed) the case where the document was created for the first
|
|
|
|
time
|
2017-07-05 06:16:42 -04:00
|
|
|
<2> Handle (if needed) the case where the document was rewritten as it was
|
2017-07-03 04:48:16 -04:00
|
|
|
already existing
|
|
|
|
<3> Handle the situation where number of successful shards is less than
|
|
|
|
total shards
|
|
|
|
<4> Handle the potential failures
|
|
|
|
|
|
|
|
If there is a version conflict, an `ElasticsearchException` will
|
|
|
|
be thrown:
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
2018-10-01 09:59:36 -04:00
|
|
|
include-tagged::{doc-tests-file}[{api}-conflict]
|
2017-07-03 04:48:16 -04:00
|
|
|
--------------------------------------------------
|
2017-07-05 05:57:57 -04:00
|
|
|
<1> The raised exception indicates that a version conflict error was returned
|
2017-07-03 04:48:16 -04:00
|
|
|
|
|
|
|
Same will happen in case `opType` was set to `create` and a document with
|
2018-12-18 08:53:49 -05:00
|
|
|
same index and id already existed:
|
2017-07-03 04:48:16 -04:00
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
2018-10-01 09:59:36 -04:00
|
|
|
include-tagged::{doc-tests-file}[{api}-optype]
|
2017-07-03 04:48:16 -04:00
|
|
|
--------------------------------------------------
|
2017-07-05 05:57:57 -04:00
|
|
|
<1> The raised exception indicates that a version conflict error was returned
|