Elasticsearch Anomaly Detection

作者 elasticbaa511126ba2无许可证592 个星标收录于 2026年10月8日更新于 2026年10月8日仓库昨天更新

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.

仅含说明DevOps & Cloud
AI 生成的概览

通过 elastic CLI 创建和管理 Elasticsearch 机器学习异常检测作业与数据源。

功能
该技能指导在时间序列索引上创建 Elastic 机器学习异常检测作业:发现目标索引和时间字段、选择计数族或均值族检测器方向,并设置桶跨度等不可变作业参数。随后创建作业及其数据源、打开作业、启动数据源,并通过统计信息确认运行状态。它还涵盖停止数据源并关闭作业的清理流程,并指向随附的参考文件以进行高级调优。
适用场景
适用于在索引或数据流上设置异常检测作业、配置作业和数据源,或打开、启动、停止、关闭作业的场景。它不用于在作业运行后解读异常分数或模型行为。
运行要求
需要 Elasticsearch 8.x+ 或具备机器学习异常检测的 Elastic Cloud Serverless、已安装并配置的 elastic CLI,以及 manage_ml 权限;自管集群需要 Platinum 等效许可证。该技能仅为说明文档,不附带脚本,但包含一份参考文档。

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 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 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 [blocked].

Full Reference

For API paths, request/response fields, score semantics, and field interactions, read references/anomaly-detection-reference.md [blocked].

Operations

HTTP API (shorthand)elastic CLI command
GET /_cat/indiceselastic es cat indices --index '<pattern>'
GET /{index}/_mappingelastic 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}/_openelastic es ml open-job --job-id '<job_id>'
POST /_ml/datafeeds/datafeed-{job_id}/_startelastic 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}/_statselastic es ml get-job-stats --job-id '<job_id>'
GET /_ml/datafeeds/datafeed-{job_id}/_statselastic es ml get-datafeed-stats --datafeed-id 'datafeed-<job_id>'
POST /_ml/datafeeds/datafeed-{job_id}/_stopelastic es ml stop-datafeed --datafeed-id 'datafeed-<job_id>'
POST /_ml/anomaly_detectors/{job_id}/_closeelastic es ml close-job --job-id '<job_id>'

来源与署名

来源:elastic/agent-skills位于skills/elasticsearch/elasticsearch-anomaly-detection提交baa5111

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架

更多来自 elastic/agent-skills 的技能

Elasticsearch Search Relevance

elastic

Improve Elasticsearch search relevance for content and catalog indices: pin or promote results with query rules (correct rule type, criteria, and rule-query wiring) and tune organic ranking with multi_match, field boosts, and analysis grounded in the index mapping. Use when search results rank poorly, a specific document must appear first for a query, or the user asks to tune full-text matching — not for ES|QL analytics, index ingest, or cluster health.

待分类592昨天更新

Elasticsearch Query Optimization

elastic

Diagnose slow Elasticsearch Query DSL searches and propose measured fixes. Use when a search is slow, profile output shows an expensive clause, exact-match filters sit in scoring context, or leading wildcards dominate latency. Ground every recommendation in search profiling — move non-scoring clauses to filter context, eliminate leading wildcards, and re-profile to confirm improvement.

待分类592昨天更新

Elasticsearch Ingest

elastic

Load CSV and JSON files into Elasticsearch indices using the bulk API and explicit mappings when field types matter. Use when batch-importing local files, converting CSV rows or JSON arrays to NDJSON bulk format, or verifying document counts and mappings after ingest — not for Logstash pipelines, Beats, custom scripts, or index-to-index reindex.

待分类592昨天更新

Elasticsearch Index Design

elastic

根据访问模式设计和审查 Elasticsearch 索引映射,涵盖字段类型、多字段和分片设置。

Data & Analytics592昨天更新

Kibana Dashboards

elastic

Create and manage Kibana Dashboards and Lens visualizations. Use when you need to define dashboards and visualizations declaratively, version control them, or automate their deployment.

待分类592昨天更新

Kibana Anomaly Detection

elastic

用于调查、解释、排查和配置 Elastic ML 异常检测作业。

Data & Analytics592昨天更新