2018-10-05 11:41:03 -04:00
|
|
|
--
|
|
|
|
:api: exists
|
|
|
|
:request: GetRequest
|
|
|
|
:response: boolean
|
|
|
|
--
|
|
|
|
|
|
|
|
[id="{upid}-{api}"]
|
2018-03-15 12:10:30 -04:00
|
|
|
=== Exists API
|
|
|
|
|
|
|
|
The exists API returns `true` if a document exists, and `false` otherwise.
|
|
|
|
|
2018-10-05 11:41:03 -04:00
|
|
|
[id="{upid}-{api}-request"]
|
2018-03-15 12:10:30 -04:00
|
|
|
==== Exists Request
|
|
|
|
|
2018-10-05 11:41:03 -04:00
|
|
|
It uses +{request}+ just like the <<java-rest-high-document-get>>.
|
2018-03-15 12:10:30 -04:00
|
|
|
All of its <<java-rest-high-document-get-request-optional-arguments, optional arguments>>
|
|
|
|
are supported. Since `exists()` only returns `true` or `false`, we recommend
|
|
|
|
turning off fetching `_source` and any stored fields so the request is
|
|
|
|
slightly lighter:
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
2018-10-05 11:41:03 -04:00
|
|
|
include-tagged::{doc-tests-file}[{api}-request]
|
2018-03-15 12:10:30 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<1> Index
|
2018-12-10 20:22:48 -05:00
|
|
|
<2> Document id
|
|
|
|
<3> Disable fetching `_source`.
|
|
|
|
<4> Disable fetching stored fields.
|
2018-03-15 12:10:30 -04:00
|
|
|
|
2018-10-05 11:41:03 -04:00
|
|
|
include::../execution.asciidoc[]
|
2018-10-26 09:21:35 -04:00
|
|
|
|
|
|
|
|
|
|
|
==== Source exists request
|
|
|
|
A variant of the exists request is `existsSource` method which has the additional check
|
|
|
|
that the document in question has stored the `source`. If the mapping for the index has opted
|
|
|
|
to remove support for storing JSON source in documents then this method will return false
|
|
|
|
for documents in this index.
|