| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 | [[java-rest-high-document-exists]]=== Exists APIThe exists API returns `true` if a document exists, and `false` otherwise.[[java-rest-high-document-exists-request]]==== Exists RequestIt uses `GetRequest` just like the <<java-rest-high-document-get>>.All of its <<java-rest-high-document-get-request-optional-arguments, optional arguments>>are supported. Since `exists()` only returns `true` or `false`, we recommendturning off fetching `_source` and any stored fields so the request isslightly lighter:["source","java",subs="attributes,callouts,macros"]--------------------------------------------------include-tagged::{doc-tests}/CRUDDocumentationIT.java[exists-request]--------------------------------------------------<1> Index<2> Type<3> Document id<4> Disable fetching `_source`.<5> Disable fetching stored fields.[[java-rest-high-document-exists-sync]]==== Synchronous Execution["source","java",subs="attributes,callouts,macros"]--------------------------------------------------include-tagged::{doc-tests}/CRUDDocumentationIT.java[exists-execute]--------------------------------------------------[[java-rest-high-document-exists-async]]==== Asynchronous ExecutionThe asynchronous execution of exists request requires both the `GetRequest`instance and an `ActionListener` instance to be passed to the asynchronousmethod:["source","java",subs="attributes,callouts,macros"]--------------------------------------------------include-tagged::{doc-tests}/CRUDDocumentationIT.java[exists-execute-async]--------------------------------------------------<1> The `GetRequest` to execute and the `ActionListener` to use whenthe execution completes.The asynchronous method does not block and returns immediately. Once it iscompleted the `ActionListener` is called back using the `onResponse` methodif the execution successfully completed or using the `onFailure` method ifit failed.A typical listener for `GetResponse` looks like:["source","java",subs="attributes,callouts,macros"]--------------------------------------------------include-tagged::{doc-tests}/CRUDDocumentationIT.java[exists-execute-listener]--------------------------------------------------<1> Called when the execution is successfully completed. The response isprovided as an argument.<2> Called in case of failure. The raised exception is provided as an argument.
 |