2018-10-29 10:32:17 -04:00
|
|
|
--
|
|
|
|
:api: multi-get
|
|
|
|
:request: MultiGetRequest
|
|
|
|
:response: MultiGetResponse
|
|
|
|
--
|
|
|
|
|
|
|
|
[id="{upid}-{api}"]
|
2018-03-16 18:52:34 -04:00
|
|
|
=== Multi-Get API
|
|
|
|
|
|
|
|
The `multiGet` API executes multiple <<java-rest-high-document-get,`get`>>
|
|
|
|
requests in a single http request in parallel.
|
|
|
|
|
2018-10-29 10:32:17 -04:00
|
|
|
[id="{upid}-{api}-request"]
|
2018-03-16 18:52:34 -04:00
|
|
|
==== Multi-Get Request
|
|
|
|
|
2018-10-29 10:32:17 -04:00
|
|
|
A +{request}+ is built empty and you add `MultiGetRequest.Item`s to configure
|
|
|
|
what to fetch:
|
2018-03-16 18:52:34 -04:00
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
2018-10-29 10:32:17 -04:00
|
|
|
include-tagged::{doc-tests-file}[{api}-request]
|
2018-03-16 18:52:34 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<1> Index
|
2018-12-10 20:22:48 -05:00
|
|
|
<2> Document id
|
|
|
|
<3> Add another item to fetch
|
2018-03-16 18:52:34 -04:00
|
|
|
|
|
|
|
==== Optional arguments
|
|
|
|
|
|
|
|
`multiGet` supports the same optional arguments that the
|
|
|
|
<<java-rest-high-document-get-request-optional-arguments,`get` API>> supports.
|
|
|
|
You can set most of these on the `Item`:
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
2018-10-29 10:32:17 -04:00
|
|
|
include-tagged::{doc-tests-file}[{api}-request-no-source]
|
2018-03-16 18:52:34 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<1> Disable source retrieval, enabled by default
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
2018-10-29 10:32:17 -04:00
|
|
|
include-tagged::{doc-tests-file}[{api}-request-source-include]
|
2018-03-16 18:52:34 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<1> Configure source inclusion for specific fields
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
2018-10-29 10:32:17 -04:00
|
|
|
include-tagged::{doc-tests-file}[{api}-request-source-exclude]
|
2018-03-16 18:52:34 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<1> Configure source exclusion for specific fields
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
2018-10-29 10:32:17 -04:00
|
|
|
include-tagged::{doc-tests-file}[{api}-request-stored]
|
2018-03-16 18:52:34 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<1> Configure retrieval for specific stored fields (requires fields to be
|
|
|
|
stored separately in the mappings)
|
|
|
|
<2> Retrieve the `foo` stored field (requires the field to be stored
|
|
|
|
separately in the mappings)
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
2018-10-29 10:32:17 -04:00
|
|
|
include-tagged::{doc-tests-file}[{api}-request-item-extras]
|
2018-03-16 18:52:34 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<1> Routing value
|
2018-04-11 10:13:54 -04:00
|
|
|
<2> Version
|
|
|
|
<3> Version type
|
2018-03-16 18:52:34 -04:00
|
|
|
|
|
|
|
{ref}/search-request-preference.html[`preference`],
|
|
|
|
{ref}/docs-get.html#realtime[`realtime`]
|
|
|
|
and
|
|
|
|
{ref}/docs-get.html#get-refresh[`refresh`] can be set on the main request but
|
|
|
|
not on any items:
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
2018-10-29 10:32:17 -04:00
|
|
|
include-tagged::{doc-tests-file}[{api}-request-top-level-extras]
|
2018-03-16 18:52:34 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<1> Preference value
|
|
|
|
<2> Set realtime flag to `false` (`true` by default)
|
|
|
|
<3> Perform a refresh before retrieving the document (`false` by default)
|
|
|
|
|
2018-10-29 10:32:17 -04:00
|
|
|
include::../execution.asciidoc[]
|
2018-03-16 18:52:34 -04:00
|
|
|
|
2018-10-29 10:32:17 -04:00
|
|
|
[id="{upid}-{api}-response"]
|
2018-03-16 18:52:34 -04:00
|
|
|
==== Multi Get Response
|
|
|
|
|
2018-10-29 10:32:17 -04:00
|
|
|
The returned +{response}+ contains a list of `MultiGetItemResponse`s in
|
2018-03-16 18:52:34 -04:00
|
|
|
`getResponses` in the same order that they were requested.
|
|
|
|
`MultiGetItemResponse` contains *either* a
|
|
|
|
<<java-rest-high-document-get-response, `GetResponse`>> if the get succeeded
|
|
|
|
or a `MultiGetResponse.Failure` if it failed. A success looks just like a
|
|
|
|
normal `GetResponse`.
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
2018-10-29 10:32:17 -04:00
|
|
|
include-tagged::{doc-tests-file}[{api}-response]
|
2018-03-16 18:52:34 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<1> `getFailure` returns null because there isn't a failure.
|
|
|
|
<2> `getResponse` returns the `GetResponse`.
|
|
|
|
<3> Retrieve the document as a `String`
|
|
|
|
<4> Retrieve the document as a `Map<String, Object>`
|
|
|
|
<5> Retrieve the document as a `byte[]`
|
|
|
|
<6> Handle the scenario where the document was not found. Note that although
|
|
|
|
the returned response has `404` status code, a valid `GetResponse` is
|
|
|
|
returned rather than an exception thrown. Such response does not hold any
|
|
|
|
source document and its `isExists` method returns `false`.
|
|
|
|
|
|
|
|
When one of the subrequests as performed against an index that does not exist
|
|
|
|
`getFailure` will contain an exception:
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
2018-10-29 10:32:17 -04:00
|
|
|
include-tagged::{doc-tests-file}[{api}-indexnotfound]
|
2018-03-16 18:52:34 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<1> `getResponse` is null.
|
|
|
|
<2> `getFailure` isn't and contains an `Exception`.
|
|
|
|
<3> That `Exception` is actually an `ElasticsearchException`
|
|
|
|
<4> and it has a status of `NOT_FOUND`. It'd have been an HTTP 404 if this
|
|
|
|
wasn't a multi get.
|
|
|
|
<5> `getMessage` explains the actual cause, `no such index`.
|
|
|
|
|
|
|
|
In case a specific document version has been requested, and the existing
|
|
|
|
document has a different version number, a version conflict is raised:
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
2018-10-29 10:32:17 -04:00
|
|
|
include-tagged::{doc-tests-file}[{api}-conflict]
|
2018-03-16 18:52:34 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<1> `getResponse` is null.
|
|
|
|
<2> `getFailure` isn't and contains an `Exception`.
|
2019-01-07 08:44:12 -05:00
|
|
|
<3> That `Exception` is actually an `ElasticsearchException`
|
2018-03-16 18:52:34 -04:00
|
|
|
<4> and it has a status of `CONFLICT`. It'd have been an HTTP 409 if this
|
|
|
|
wasn't a multi get.
|
|
|
|
<5> `getMessage` explains the actual cause, `
|