get-records.asciidoc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. [[java-rest-high-x-pack-ml-get-records]]
  2. === Get Records API
  3. The Get Records API retrieves one or more record results.
  4. It accepts a `GetRecordsRequest` object and responds
  5. with a `GetRecordsResponse` object.
  6. [[java-rest-high-x-pack-ml-get-records-request]]
  7. ==== Get Records Request
  8. A `GetRecordsRequest` object gets created with an existing non-null `jobId`.
  9. ["source","java",subs="attributes,callouts,macros"]
  10. --------------------------------------------------
  11. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-records-request]
  12. --------------------------------------------------
  13. <1> Constructing a new request referencing an existing `jobId`
  14. ==== Optional Arguments
  15. The following arguments are optional:
  16. ["source","java",subs="attributes,callouts,macros"]
  17. --------------------------------------------------
  18. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-records-desc]
  19. --------------------------------------------------
  20. <1> If `true`, the records are sorted in descending order. Defaults to `false`.
  21. ["source","java",subs="attributes,callouts,macros"]
  22. --------------------------------------------------
  23. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-records-end]
  24. --------------------------------------------------
  25. <1> Records with timestamps earlier than this time will be returned.
  26. ["source","java",subs="attributes,callouts,macros"]
  27. --------------------------------------------------
  28. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-records-exclude-interim]
  29. --------------------------------------------------
  30. <1> If `true`, interim results will be excluded. Defaults to `false`.
  31. ["source","java",subs="attributes,callouts,macros"]
  32. --------------------------------------------------
  33. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-records-page]
  34. --------------------------------------------------
  35. <1> The page parameters `from` and `size`. `from` specifies the number of records to skip.
  36. `size` specifies the maximum number of records to get. Defaults to `0` and `100` respectively.
  37. ["source","java",subs="attributes,callouts,macros"]
  38. --------------------------------------------------
  39. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-records-record-score]
  40. --------------------------------------------------
  41. <1> Records with record_score greater or equal than this value will be returned.
  42. ["source","java",subs="attributes,callouts,macros"]
  43. --------------------------------------------------
  44. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-records-sort]
  45. --------------------------------------------------
  46. <1> The field to sort records on. Defaults to `record_score`.
  47. ["source","java",subs="attributes,callouts,macros"]
  48. --------------------------------------------------
  49. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-records-start]
  50. --------------------------------------------------
  51. <1> Records with timestamps on or after this time will be returned.
  52. [[java-rest-high-x-pack-ml-get-records-execution]]
  53. ==== Execution
  54. The request can be executed through the `MachineLearningClient` contained
  55. in the `RestHighLevelClient` object, accessed via the `machineLearningClient()` method.
  56. ["source","java",subs="attributes,callouts,macros"]
  57. --------------------------------------------------
  58. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-records-execute]
  59. --------------------------------------------------
  60. [[java-rest-high-x-pack-ml-get-records-execution-async]]
  61. ==== Asynchronous Execution
  62. The request can also be executed asynchronously:
  63. ["source","java",subs="attributes,callouts,macros"]
  64. --------------------------------------------------
  65. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-records-execute-async]
  66. --------------------------------------------------
  67. <1> The `GetRecordsRequest` to execute and the `ActionListener` to use when
  68. the execution completes
  69. The asynchronous method does not block and returns immediately. Once it is
  70. completed the `ActionListener` is called back with the `onResponse` method
  71. if the execution is successful or the `onFailure` method if the execution
  72. failed.
  73. A typical listener for `GetRecordsResponse` looks like:
  74. ["source","java",subs="attributes,callouts,macros"]
  75. --------------------------------------------------
  76. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-records-listener]
  77. --------------------------------------------------
  78. <1> `onResponse` is called back when the action is completed successfully
  79. <2> `onFailure` is called back when some unexpected error occurs
  80. [[java-rest-high-x-pack-ml-get-records-response]]
  81. ==== Get Records Response
  82. The returned `GetRecordsResponse` contains the requested records:
  83. ["source","java",subs="attributes,callouts,macros"]
  84. --------------------------------------------------
  85. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-records-response]
  86. --------------------------------------------------
  87. <1> The count of records that were matched
  88. <2> The records retrieved