2018-10-05 11:41:03 -04:00
|
|
|
--
|
|
|
|
:api: get
|
|
|
|
:request: GetRequest
|
|
|
|
:response: GetResponse
|
|
|
|
--
|
|
|
|
|
|
|
|
[id="{upid}-{api}"]
|
2017-07-05 05:57:57 -04:00
|
|
|
=== Get API
|
|
|
|
|
2018-10-05 11:41:03 -04:00
|
|
|
[id="{upid}-{api}-request"]
|
2017-07-05 05:57:57 -04:00
|
|
|
==== Get Request
|
|
|
|
|
2018-10-05 11:41:03 -04:00
|
|
|
A +{request}+ requires the following arguments:
|
2017-07-05 05:57:57 -04:00
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
2018-10-05 11:41:03 -04:00
|
|
|
include-tagged::{doc-tests-file}[{api}-request]
|
2017-07-05 05:57:57 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<1> Index
|
|
|
|
<2> Type
|
|
|
|
<3> Document id
|
|
|
|
|
2018-10-05 11:41:03 -04:00
|
|
|
[id="{upid}-{api}-request-optional-arguments"]
|
2017-07-05 05:57:57 -04:00
|
|
|
==== Optional arguments
|
|
|
|
The following arguments can optionally be provided:
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
2018-10-05 11:41:03 -04:00
|
|
|
include-tagged::{doc-tests-file}[{api}-request-no-source]
|
2017-07-05 05:57:57 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<1> Disable source retrieval, enabled by default
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
2018-10-05 11:41:03 -04:00
|
|
|
include-tagged::{doc-tests-file}[{api}-request-source-include]
|
2017-07-05 05:57:57 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<1> Configure source inclusion for specific fields
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
2018-10-05 11:41:03 -04:00
|
|
|
include-tagged::{doc-tests-file}[{api}-request-source-exclude]
|
2017-07-05 05:57:57 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<1> Configure source exclusion for specific fields
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
2018-10-05 11:41:03 -04:00
|
|
|
include-tagged::{doc-tests-file}[{api}-request-stored]
|
2017-07-05 05:57:57 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<1> Configure retrieval for specific stored fields (requires fields to be
|
|
|
|
stored separately in the mappings)
|
|
|
|
<2> Retrieve the `message` stored field (requires the field to be stored
|
|
|
|
separately in the mappings)
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
2018-10-05 11:41:03 -04:00
|
|
|
include-tagged::{doc-tests-file}[{api}-request-routing]
|
2017-07-05 05:57:57 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<1> Routing value
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
2018-10-05 11:41:03 -04:00
|
|
|
include-tagged::{doc-tests-file}[{api}-request-preference]
|
2017-07-05 05:57:57 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<1> Preference value
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
2018-10-05 11:41:03 -04:00
|
|
|
include-tagged::{doc-tests-file}[{api}-request-realtime]
|
2017-07-05 05:57:57 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<1> Set realtime flag to `false` (`true` by default)
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
2018-10-05 11:41:03 -04:00
|
|
|
include-tagged::{doc-tests-file}[{api}-request-refresh]
|
2017-07-05 05:57:57 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<1> Perform a refresh before retrieving the document (`false` by default)
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
2018-10-05 11:41:03 -04:00
|
|
|
include-tagged::{doc-tests-file}[{api}-request-version]
|
2017-07-05 05:57:57 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<1> Version
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
2018-10-05 11:41:03 -04:00
|
|
|
include-tagged::{doc-tests-file}[{api}-request-version-type]
|
2017-07-05 05:57:57 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<1> Version type
|
|
|
|
|
2018-10-05 11:41:03 -04:00
|
|
|
include::../execution.asciidoc[]
|
2017-07-05 05:57:57 -04:00
|
|
|
|
2018-10-05 11:41:03 -04:00
|
|
|
[id="{upid}-{api}-response"]
|
2017-07-05 05:57:57 -04:00
|
|
|
==== Get Response
|
|
|
|
|
2018-10-05 11:41:03 -04:00
|
|
|
The returned +{response}+ allows to retrieve the requested document along with
|
2017-07-05 05:57:57 -04:00
|
|
|
its metadata and eventually stored fields.
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
2018-10-05 11:41:03 -04:00
|
|
|
include-tagged::{doc-tests-file}[{api}-response]
|
2017-07-05 05:57:57 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<1> Retrieve the document as a `String`
|
|
|
|
<2> Retrieve the document as a `Map<String, Object>`
|
|
|
|
<3> Retrieve the document as a `byte[]`
|
|
|
|
<4> Handle the scenario where the document was not found. Note that although
|
2018-10-05 11:41:03 -04:00
|
|
|
the returned response has `404` status code, a valid +{response}+ is
|
2017-07-05 05:57:57 -04:00
|
|
|
returned rather than an exception thrown. Such response does not hold any
|
|
|
|
source document and its `isExists` method returns `false`.
|
|
|
|
|
|
|
|
When a get request is performed against an index that does not exist, the
|
|
|
|
response has `404` status code, an `ElasticsearchException` gets thrown
|
|
|
|
which needs to be handled as follows:
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
2018-10-05 11:41:03 -04:00
|
|
|
include-tagged::{doc-tests-file}[{api}-indexnotfound]
|
2017-07-05 05:57:57 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<1> Handle the exception thrown because the index does not exist
|
|
|
|
|
|
|
|
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-05 11:41:03 -04:00
|
|
|
include-tagged::{doc-tests-file}[{api}-conflict]
|
2017-07-05 05:57:57 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<1> The raised exception indicates that a version conflict error was returned
|