elasticsearch/docs/reference/ml/anomaly-detection/apis/reset-job.asciidoc
Dimitris Athanasiou dc61a72c9e
[ML] Reset anomaly detection job API (#73908)
Adds a new API that allows a user to reset
an anomaly detection job.

To use the API do:

```
POST _ml/anomaly_detectors/<job_id>_reset
```

The API removes all data associated to the job.
In particular, it deletes model state, results and stats.

However, job notifications and user annotations are not removed.

Also, the API can be called asynchronously by setting the parameter
`wait_for_completion` to `false` (defaults to `true`). When run
that way the API returns the task id for further monitoring.

In order to prevent the job from opening while it is resetting,
a new job field has been added called `blocked`. It is an object
that contains a `reason` and the `task_id`. `reason` can take
a value from ["delete", "reset", "revert"] as all these
operations should block the job from opening. The `task_id` is also
included in order to allow tracking the task if necessary.

Finally, this commit also sets the `blocked` field when
the revert snapshot API is called as a job should not be opened
while it is reverted to a different model snapshot.
2021-06-14 18:56:28 +03:00

86 lines
2.2 KiB
Text

[role="xpack"]
[testenv="platinum"]
[[ml-reset-job]]
= Reset {anomaly-jobs} API
++++
<titleabbrev>Reset jobs</titleabbrev>
++++
Resets an existing {anomaly-job}.
[[ml-reset-job-request]]
== {api-request-title}
`POST _ml/anomaly_detectors/<job_id>/_reset`
[[ml-reset-job-prereqs]]
== {api-prereq-title}
* Requires the `manage_ml` cluster privilege. This privilege is included in the
`machine_learning_admin` built-in role.
* Before you can reset a job, you must close it. You can set `force` to `true`
when closing the job to avoid waiting for the job to complete. See
<<ml-close-job>>.
[[ml-reset-job-desc]]
== {api-description-title}
All model state and results are deleted.
The job is ready to start over as if it had just been created.
It is not currently possible to reset multiple jobs using wildcards or a comma
separated list.
[[ml-reset-job-path-parms]]
== {api-path-parms-title}
`<job_id>`::
(Required, string)
include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=job-id-anomaly-detection]
[[ml-reset-job-query-parms]]
== {api-query-parms-title}
`wait_for_completion`::
(Optional, Boolean) Specifies whether the request should return immediately or
wait until the job reset completes. Defaults to `true`.
[[ml-reset-job-example]]
== {api-examples-title}
[source,console]
--------------------------------------------------
POST _ml/anomaly_detectors/total-requests/_reset
--------------------------------------------------
// TEST[skip:setup:server_metrics_job]
When the job is reset, you receive the following results:
[source,console-result]
----
{
"acknowledged": true
}
----
In the next example we reset the `total-requests` job asynchronously:
[source,console]
--------------------------------------------------
POST _ml/anomaly_detectors/total-requests/_reset?wait_for_completion=false
--------------------------------------------------
// TEST[skip:setup:server_metrics_job]
When `wait_for_completion` is set to `false`, the response contains the id
of the job reset task:
[source,console-result]
----
{
"task": "oTUltX4IQMOUUVeiohTt8A:39"
}
----
// TESTRESPONSE[s/"task": "oTUltX4IQMOUUVeiohTt8A:39"/"task": $body.task/]
If you want to check the status of the reset task, use the <<tasks>> by referencing
the task ID.