exists.asciidoc 1.2 KB

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