Installation
Install as Agent Plugin
Recommended
copilot plugin marketplace add samueltauil/skills-hub
copilot plugin install elasticsearch-anomaly-detection@skills-hub
Works with GitHub Copilot CLI and VS Code (enable chat.plugins.enabled).
Plugin elasticsearch-anomaly-detection v1.0.0 follows the Agent Plugins spec.
Install with the gh extension
gh skills-hub install elasticsearch-anomaly-detection Don't have the extension? Run gh extension install samueltauil/skills-hub first.
Download and extract to your repository:
.github/skills/elasticsearch-anomaly-detection/ Extract the ZIP to .github/skills/ in your repo. The folder name must match elasticsearch-anomaly-detection for Copilot to auto-discover it.
Skill Files (2)
SKILL.md 9.3 KB
---
name: elasticsearch-anomaly-detection
description: >
Create and manage Elastic ML anomaly detection jobs via the API. Use when setting
up jobs on an index or data stream, configuring jobs and datafeeds, or opening,
starting, or stopping them.
compatibility: >
Requires Elasticsearch 8.x+ or Elastic Cloud Serverless with ML anomaly detection.
Uses the ML REST API only. User needs manage_ml privilege to create and manage jobs.
metadata:
author: elastic
version: 1.1.0
universal: true
---
# Elasticsearch Anomaly Detection
Create, open, and start ML anomaly detection jobs on time-series data. Choose the right count-family detector direction,
configure bucket span and time field, wire the datafeed to the correct index, and confirm running state from stats — not
from assumptions.
<!-- begin-partial: preamble -->
## Environment Configuration
This skill executes Elasticsearch operations through the `elastic` CLI. If the
[`elastic` CLI](https://github.com/elastic/cli#configuration) is not installed, tell the user what it is needed for. Do
not guess credentials, call the HTTP API directly, or attempt other workarounds.
This skill references operations in HTTP-shorthand form (e.g., `GET /`, `GET /_cat/indices`, `GET /{index}/_mapping`,
`GET /{index}/_settings/index.mode`, `POST /_query`). The [Operations](#operations) table at the end of this document
maps each shorthand to the equivalent `elastic` CLI command — always use the CLI rather than calling the HTTP API
directly.
<!-- end-partial: preamble -->
> **Prerequisite:** ML anomaly detection requires a Platinum-equivalent license on self-managed clusters. Serverless
> projects include ML. The caller needs `manage_ml` to create and manage jobs.
>
> **Related skill:** For interpreting anomaly scores, influencers, and model behavior after a job is running, use
> `elasticsearch-anomaly-detection-explainer` — not this skill.
## Process
1. **Discover the target index and time field.** List candidate indices with `GET /_cat/indices` (pass a pattern when
the user names one). Fetch field types for the chosen index with `GET /{index}/_mapping`. The decision: confirm the
index exists, identify the time field (often `@timestamp`), and verify document volume is sufficient for baseline
learning. Never guess index or field names — they vary across deployments.
2. **Choose detector function and direction.** Match the user's intent to a count-family detector in
`analysis_config.detectors`:
- **Spike, surge, unusual increase in event volume** → `high_count` (or `count`, which flags both directions but is
acceptable when the user cares about spikes). Do **not** use `low_count` — it will miss spikes.
- **Drop, outage, absence of events, traffic stops** → `low_count`. Do **not** use `high_count` — it will miss drops
and silence.
- **Metric deviation** (CPU, latency, a numeric field) → mean-family functions (`mean`, `high_mean`, `low_mean`) with
`field_name` set — only when the user asks about a numeric metric, not raw event volume.
The decision: pick one primary detector whose direction matches the anomaly type. For volume spike/drop questions on
document counts, stay in the count family — mean detectors are unsuited to "how many events" questions.
3. **Set immutable job shape before creation.** These fields cannot change after `PUT /_ml/anomaly_detectors/{job_id}`:
- `analysis_config.bucket_span` — use the interval the user specifies (e.g. `15m` for 15-minute buckets). Match the
granularity of anomalies they care about; too short is noisy, too long is slow to detect.
- `data_description.time_field` — the time field from the mapping (commonly `@timestamp`).
- `analysis_config.detectors` — the function and direction from step 2.
Example job body for a volume-spike detector:
```json
{
"analysis_config": {
"bucket_span": "15m",
"detectors": [{ "function": "high_count" }]
},
"data_description": { "time_field": "@timestamp" }
}
```
Example for an outage / drop detector:
```json
{
"analysis_config": {
"bucket_span": "15m",
"detectors": [{ "function": "low_count" }]
},
"data_description": { "time_field": "@timestamp" }
}
```
4. **Create the job.** Call `PUT /_ml/anomaly_detectors/{job_id}` with the job id the user requested (or a descriptive
id you propose). The job starts in `closed` state — creating it does not start analysis.
5. **Create the datafeed.** Call `PUT /_ml/datafeeds/datafeed-{job_id}` immediately after job creation. Set `job_id` to
the same id, `indices` to the target index (exact name or pattern from step 1), and a query that selects the relevant
documents (typically `match_all`). The datafeed id convention is `datafeed-{job_id}`.
```json
{
"job_id": "{job_id}",
"indices": ["{index}"],
"query": { "match_all": {} }
}
```
6. **Open the job, then start the datafeed — in that order.** This sequence is mandatory; do not skip or reorder:
1. `POST /_ml/anomaly_detectors/{job_id}/_open` — transitions the job to `opened`.
2. `POST /_ml/datafeeds/datafeed-{job_id}/_start` — transitions the datafeed to `started`.
Opening before the datafeed exists fails. Starting the datafeed before opening the job fails. Do not report success
after only creating resources — the job is not running until both are active.
7. **Confirm running state from stats.** Verify the outcome with:
- `GET /_ml/anomaly_detectors/{job_id}/_stats` — expect `state: "opened"`.
- `GET /_ml/datafeeds/datafeed-{job_id}/_stats` — expect `state: "started"`.
Optionally call `GET /_ml/anomaly_detectors/{job_id}` to confirm configuration (detectors, `bucket_span`,
`time_field`, datafeed indices). Report both stats states explicitly — "created" is not the same as "opened" and
"started".
## Teardown
When stopping or deleting a job, reverse the startup order:
1. `POST /_ml/datafeeds/datafeed-{job_id}/_stop` — stop the datafeed first.
2. `POST /_ml/anomaly_detectors/{job_id}/_close` — then close the job.
Stop the datafeed before closing the job. Close the job before resetting or deleting it.
## Guidelines
- **Required lifecycle order (create):** job → datafeed → open job → start datafeed. Every new job follows this
sequence.
- **Detector direction is the highest-impact decision** for volume anomalies. Re-read the user's wording: "spike",
"surge", and "unusual increase" → high direction; "drop", "outage", "stops", "absence" → low direction.
- **Immutable fields** (`bucket_span`, detectors, `time_field`) require delete-and-recreate if wrong — validate mapping
and intent before the first `PUT`.
- **Datafeed index must match the user's target.** Point `indices` at the exact index or pattern they named — not a
nearby guess.
- **Entity-level analysis** (`by_field_name`, `over_field_name`, `partition_field_name`) and advanced tuning live in
[references/anomaly-detection-reference.md](references/anomaly-detection-reference.md).
## Full Reference
For API paths, request/response fields, score semantics, and field interactions, read
[references/anomaly-detection-reference.md](references/anomaly-detection-reference.md).
## Operations
| HTTP API (shorthand) | `elastic` CLI command |
| ---------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| `GET /_cat/indices` | `elastic es cat indices --index '<pattern>'` |
| `GET /{index}/_mapping` | `elastic es indices get-mapping --index '<index>'` |
| `PUT /_ml/anomaly_detectors/{job_id}` | `elastic es ml put-job --job-id '<job_id>' --analysis-config '<json>' --data-description '<json>'` |
| `PUT /_ml/datafeeds/datafeed-{job_id}` | `elastic es ml put-datafeed --datafeed-id 'datafeed-<job_id>' --job-id '<job_id>' --indices '<index>' --query '<json>'` |
| `POST /_ml/anomaly_detectors/{job_id}/_open` | `elastic es ml open-job --job-id '<job_id>'` |
| `POST /_ml/datafeeds/datafeed-{job_id}/_start` | `elastic es ml start-datafeed --datafeed-id 'datafeed-<job_id>'` |
| `GET /_ml/anomaly_detectors/{job_id}` | `elastic es ml get-jobs --job-id '<job_id>'` |
| `GET /_ml/anomaly_detectors/{job_id}/_stats` | `elastic es ml get-job-stats --job-id '<job_id>'` |
| `GET /_ml/datafeeds/datafeed-{job_id}/_stats` | `elastic es ml get-datafeed-stats --datafeed-id 'datafeed-<job_id>'` |
| `POST /_ml/datafeeds/datafeed-{job_id}/_stop` | `elastic es ml stop-datafeed --datafeed-id 'datafeed-<job_id>'` |
| `POST /_ml/anomaly_detectors/{job_id}/_close` | `elastic es ml close-job --job-id '<job_id>'` |
references/
anomaly-detection-reference.md 6.3 KB
# Anomaly Detection API and concepts
## API paths
```json
PUT /_ml/anomaly_detectors/<job_id>
POST /_ml/anomaly_detectors/<job_id>/_update
POST /_ml/anomaly_detectors/<job_id>/_open
POST /_ml/anomaly_detectors/<job_id>/_close
POST /_ml/anomaly_detectors/<job_id>/_flush
POST /_ml/anomaly_detectors/<job_id>/_reset
GET /_ml/anomaly_detectors/<job_id>/_stats
DELETE /_ml/anomaly_detectors/<job_id>
PUT /_ml/datafeeds/datafeed-<job_id>
POST /_ml/datafeeds/datafeed-<job_id>/_update
POST /_ml/datafeeds/datafeed-<job_id>/_start
POST /_ml/datafeeds/datafeed-<job_id>/_stop
GET /_ml/datafeeds/datafeed-<job_id>/_stats
GET /_ml/datafeeds/datafeed-<job_id>/_preview
DELETE /_ml/datafeeds/datafeed-<job_id>
GET /_ml/anomaly_detectors/<job_id>/results/buckets
GET /_ml/anomaly_detectors/<job_id>/results/records
GET /_ml/anomaly_detectors/<job_id>/results/influencers
POST /_ml/anomaly_detectors/<job_id>/results/overall_buckets
GET /_ml/anomaly_detectors/<job_id>/model_snapshots
POST /_ml/anomaly_detectors/<job_id>/model_snapshots/<snap_id>/_revert
PUT /_ml/filters/<filter_id>
PUT /_ml/calendars/<calendar_id>
POST /_ml/calendars/<calendar_id>/events
```
## Anomaly Scores
- **record_score** (0-100): Severity of a single anomaly record. >75 = critical, 50-75 = warning, 25-50 = minor, <25 =
informational.
- **anomaly_score** (bucket-level): Overall severity for a time bucket across all detectors in a job.
- **influencer_score**: How unusual an entity is within a time bucket. Entities appearing across multiple jobs with high
scores are strong root-cause candidates.
- **initial_record_score** vs **record_score**: If initial >> current, the model renormalized the anomaly downward after
seeing more data. Use initial_record_score for alerting on fresh anomalies.
- **multi_bucket_impact**: Positive values (0-5) indicate sustained anomalies spanning multiple buckets. Values >= 3
suggest a genuine behavioral shift, not a transient spike.
## Key Concepts
- **Influencers**: Entities (hosts, users, services, IPs) that contribute to anomalies. Cross-job shared influencers are
the strongest RCA signal.
- **by_field**: Splits analysis into independent baselines per entity (e.g., per-user, per-host).
- **over_field**: Population analysis — compares each entity against its peer group.
- **partition_field**: Splits the model into independent partitions (e.g., per-datacenter).
## Job state machine
```text
closed → opening → opened → closing → closed
↘ failed → closed (requires ?force=true on _close)
```
Stop the datafeed before closing the job. Close the job before resetting or reverting a snapshot.
## Immutable after job creation
These cannot be changed with `_update` — changing them requires deleting and recreating the job:
- `analysis_config.bucket_span`
- `analysis_config.detectors` (add or remove)
- `data_description.time_field`
- `results_index_name`
## Non-obvious field interactions
**`bucket_span`** — Choose based on the granularity of anomalies the user cares about, not on data frequency. Too short
→ noisy; too long → slow to detect.
**`by_field_name` vs `over_field_name` vs `partition_field_name`**
- `by_field_name` — separate model per value; detects deviation from each value's own history.
- `over_field_name` — one shared population model; detects individuals that deviate from their peers. Use this for "who
is the outlier right now" questions.
- `partition_field_name` — fully isolated model per value; higher memory cost than `by_field_name`. Use only when
partitions are genuinely independent (for example, separate tenants).
**`query_delay` vs `latency`**
- `query_delay` (datafeed) — how far behind real time the datafeed searches. Increase when source data arrives late.
- `latency` (job `analysis_config`) — buffer for out-of-order records within the job. Adds processing lag equal to its
value.
**`summary_count_field_name`** — Required in `analysis_config` whenever the datafeed uses aggregations. Must match the
field in the aggregation output that holds the document count.
## Renormalization
Elasticsearch continuously renormalizes scores relative to the most extreme anomaly ever seen by the job. A score of 90
today might become 60 next week if a more extreme anomaly appears. This is by design — it ensures the "worst ever" event
always scores near 100.
## multi_bucket_impact
Positive values (0-5) indicate an anomaly that spans multiple consecutive buckets. Values >= 3 suggest a genuine
sustained behavioral shift rather than a transient spike. A single-bucket anomaly with no multi_bucket_impact is likely
a one-off event.
## Indices
| Index | Contents | Queryable |
| ------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------ |
| `.ml-anomalies-shared` | Default results (buckets, records, influencers) for all jobs | Yes — filter by `job_id` and `result_type` |
| `.ml-anomalies-custom-<suffix>` | Results when `results_index_name` is set on the job | Yes — same approach |
| `.ml-state-*` | Model state and snapshots | No — internal only; use the snapshots API |
| `.ml-stats-*` | Job and datafeed stats history | Yes — read-only; prefer `_stats` API for current state |
| `.ml-notifications-*` | Audit log: job lifecycle events, errors, warnings | Yes — useful for diagnosing silent failures |
| `.ml-config` | Job and datafeed definitions (internal store) | No — internal only; use the ML REST API |
| `.ml-annotations-*` | User and system annotations on anomaly charts | Yes — read-only; filter by `job_id` and `type` |
## Further reading
Full field documentation if fetch is available:
- Job: `https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-ml-put-job`
- Datafeed: `https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-ml-put-datafeed`
- Detector functions: `https://www.elastic.co/guide/en/machine-learning/current/ml-functions.html`
License (Apache-2.0)
Apache-2.0
Source: elastic/agent-skills
View full license text
Licensed under the Apache License, Version 2.0. See https://github.com/elastic/agent-skills/blob/main/LICENSE