OpenSearch/docs/java-rest/high-level/ml/get-datafeed-stats.asciidoc

67 lines
3.1 KiB
Plaintext
Raw Normal View History

[[java-rest-high-x-pack-ml-get-datafeed-stats]]
=== Get Datafeed Stats API
The Get Datafeed Stats API provides the ability to get any number of
{ml} datafeed's statistics in the cluster.
It accepts a `GetDatafeedStatsRequest` object and responds
with a `GetDatafeedStatsResponse` object.
[[java-rest-high-x-pack-ml-get-datafeed-stats-request]]
==== Get Datafeed Stats Request
A `GetDatafeedStatsRequest` object can have any number of `datafeedId`
entries. However, they all must be non-null. An empty list is the same as
requesting statistics for all datafeeds.
["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-datafeed-stats-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-stats-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-stats-execute]
--------------------------------------------------
[[java-rest-high-x-pack-ml-get-datafeed-stats-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-stats-execute-async]
--------------------------------------------------
<1> The `GetDatafeedStatsRequest` 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 `GetDatafeedStatsResponse` may
look like
["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-datafeed-stats-listener]
--------------------------------------------------
<1> `onResponse` is called back when the action is completed successfully
<2> `onFailure` is called back when some unexpected error occurs
[[java-rest-high-x-pack-ml-get-datafeed-stats-response]]
==== Get Datafeed Stats Response
The returned `GetDatafeedStatsResponse` contains the requested datafeed statistics:
["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-datafeed-stats-response]
--------------------------------------------------
<1> `count()` indicates the number of datafeeds statistics found
<2> `datafeedStats()` is the collection of {ml} `DatafeedStats` objects found