get.asciidoc 4.8 KB

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