get.asciidoc 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. [[java-rest-high-document-get]]
  2. === Get API
  3. [[java-rest-high-document-get-request]]
  4. ==== Get Request
  5. A `GetRequest` requires the following arguments:
  6. ["source","java",subs="attributes,callouts,macros"]
  7. --------------------------------------------------
  8. include-tagged::{doc-tests}/CRUDDocumentationIT.java[get-request]
  9. --------------------------------------------------
  10. <1> Index
  11. <2> Type
  12. <3> Document id
  13. ==== Optional arguments
  14. The following arguments can optionally be provided:
  15. ["source","java",subs="attributes,callouts,macros"]
  16. --------------------------------------------------
  17. include-tagged::{doc-tests}/CRUDDocumentationIT.java[get-request-no-source]
  18. --------------------------------------------------
  19. <1> Disable source retrieval, enabled by default
  20. ["source","java",subs="attributes,callouts,macros"]
  21. --------------------------------------------------
  22. include-tagged::{doc-tests}/CRUDDocumentationIT.java[get-request-source-include]
  23. --------------------------------------------------
  24. <1> Configure source inclusion for specific fields
  25. ["source","java",subs="attributes,callouts,macros"]
  26. --------------------------------------------------
  27. include-tagged::{doc-tests}/CRUDDocumentationIT.java[get-request-source-exclude]
  28. --------------------------------------------------
  29. <1> Configure source exclusion for specific fields
  30. ["source","java",subs="attributes,callouts,macros"]
  31. --------------------------------------------------
  32. include-tagged::{doc-tests}/CRUDDocumentationIT.java[get-request-stored]
  33. --------------------------------------------------
  34. <1> Configure retrieval for specific stored fields (requires fields to be
  35. stored separately in the mappings)
  36. <2> Retrieve the `message` stored field (requires the field to be stored
  37. separately in the mappings)
  38. ["source","java",subs="attributes,callouts,macros"]
  39. --------------------------------------------------
  40. include-tagged::{doc-tests}/CRUDDocumentationIT.java[get-request-routing]
  41. --------------------------------------------------
  42. <1> Routing value
  43. ["source","java",subs="attributes,callouts,macros"]
  44. --------------------------------------------------
  45. include-tagged::{doc-tests}/CRUDDocumentationIT.java[get-request-parent]
  46. --------------------------------------------------
  47. <1> Parent value
  48. ["source","java",subs="attributes,callouts,macros"]
  49. --------------------------------------------------
  50. include-tagged::{doc-tests}/CRUDDocumentationIT.java[get-request-preference]
  51. --------------------------------------------------
  52. <1> Preference value
  53. ["source","java",subs="attributes,callouts,macros"]
  54. --------------------------------------------------
  55. include-tagged::{doc-tests}/CRUDDocumentationIT.java[get-request-realtime]
  56. --------------------------------------------------
  57. <1> Set realtime flag to `false` (`true` by default)
  58. ["source","java",subs="attributes,callouts,macros"]
  59. --------------------------------------------------
  60. include-tagged::{doc-tests}/CRUDDocumentationIT.java[get-request-refresh]
  61. --------------------------------------------------
  62. <1> Perform a refresh before retrieving the document (`false` by default)
  63. ["source","java",subs="attributes,callouts,macros"]
  64. --------------------------------------------------
  65. include-tagged::{doc-tests}/CRUDDocumentationIT.java[get-request-version]
  66. --------------------------------------------------
  67. <1> Version
  68. ["source","java",subs="attributes,callouts,macros"]
  69. --------------------------------------------------
  70. include-tagged::{doc-tests}/CRUDDocumentationIT.java[get-request-version-type]
  71. --------------------------------------------------
  72. <1> Version type
  73. [[java-rest-high-document-get-sync]]
  74. ==== Synchronous Execution
  75. ["source","java",subs="attributes,callouts,macros"]
  76. --------------------------------------------------
  77. include-tagged::{doc-tests}/CRUDDocumentationIT.java[get-execute]
  78. --------------------------------------------------
  79. [[java-rest-high-document-get-async]]
  80. ==== Asynchronous Execution
  81. ["source","java",subs="attributes,callouts,macros"]
  82. --------------------------------------------------
  83. include-tagged::{doc-tests}/CRUDDocumentationIT.java[get-execute-async]
  84. --------------------------------------------------
  85. <1> Called when the execution is successfully completed. The response is
  86. provided as an argument.
  87. <2> Called in case of failure. The raised exception is provided as an argument.
  88. [[java-rest-high-document-get-response]]
  89. ==== Get Response
  90. The returned `GetResponse` allows to retrieve the requested document along with
  91. its metadata and eventually stored fields.
  92. ["source","java",subs="attributes,callouts,macros"]
  93. --------------------------------------------------
  94. include-tagged::{doc-tests}/CRUDDocumentationIT.java[get-response]
  95. --------------------------------------------------
  96. <1> Retrieve the document as a `String`
  97. <2> Retrieve the document as a `Map<String, Object>`
  98. <3> Retrieve the document as a `byte[]`
  99. <4> Handle the scenario where the document was not found. Note that although
  100. the returned response has `404` status code, a valid `GetResponse` is
  101. returned rather than an exception thrown. Such response does not hold any
  102. source document and its `isExists` method returns `false`.
  103. When a get request is performed against an index that does not exist, the
  104. response has `404` status code, an `ElasticsearchException` gets thrown
  105. which needs to be handled as follows:
  106. ["source","java",subs="attributes,callouts,macros"]
  107. --------------------------------------------------
  108. include-tagged::{doc-tests}/CRUDDocumentationIT.java[get-indexnotfound]
  109. --------------------------------------------------
  110. <1> Handle the exception thrown because the index does not exist
  111. In case a specific document version has been requested, and the existing
  112. document has a different version number, a version conflict is raised:
  113. ["source","java",subs="attributes,callouts,macros"]
  114. --------------------------------------------------
  115. include-tagged::{doc-tests}/CRUDDocumentationIT.java[get-conflict]
  116. --------------------------------------------------
  117. <1> The raised exception indicates that a version conflict error was returned