[[java-rest-high-x-pack-ml-get-datafeed]] === Get Datafeed API The Get Datafeed API provides the ability to get {ml} datafeeds in the cluster. It accepts a `GetDatafeedRequest` object and responds with a `GetDatafeedResponse` object. [[java-rest-high-x-pack-ml-get-datafeed-request]] ==== Get Datafeed Request A `GetDatafeedRequest` object gets can have any number of `datafeedId` entries. However, they all must be non-null. An empty list is the same as requesting for all datafeeds. ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-datafeed-request] -------------------------------------------------- <1> Constructing a new request referencing existing `datafeedIds`, can contain wildcards <2> Whether to ignore if a wildcard expression matches no datafeeds. (This includes `_all` string or when no datafeeds have been specified) [[java-rest-high-x-pack-ml-get-datafeed-execution]] ==== Execution The request can be executed through the `MachineLearningClient` contained in the `RestHighLevelClient` object, accessed via the `machineLearningClient()` method. ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-datafeed-execute] -------------------------------------------------- <1> The count of retrieved datafeeds <2> The retrieved datafeeds [[java-rest-high-x-pack-ml-get-datafeed-execution-async]] ==== Asynchronous Execution The request can also be executed asynchronously: ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-datafeed-execute-async] -------------------------------------------------- <1> The `GetDatafeedRequest` to execute and the `ActionListener` to use when the execution completes The method does not block and returns immediately. The passed `ActionListener` is used to notify the caller of completion. A typical `ActionListener` for `GetDatafeedResponse` may look like ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-datafeed-listener] -------------------------------------------------- <1> `onResponse` is called back when the action is completed successfully <2> `onFailure` is called back when some unexpected error occurs