get.asciidoc 4.8 KB

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