Skip to content

Anomaly Detection

OpenSearch anomaly detection automatically identifies unusual patterns in log data without requiring manual threshold configuration. It learns baseline behavior and scores deviations as anomaly grades (0.0–1.0).

DetectorIndexFeaturesCategory Fields
payment-latency-detectorpayment_queriesavg_response_time, max_response_timemethod
external-service-latency-detectorexternal_service_callsavg_response_time, max_response_timeservice, method
database-latency-detectordatabase_queriesavg_response_time, max_response_timequery_type, table_name
GradeSeverityMeaning
≥ 0.8CRITICALSevere deviation from baseline
≥ 0.6HIGHSignificant anomaly
≥ 0.4MEDIUMNotable deviation
≥ 0.2LOWMinor deviation
< 0.2NORMALWithin expected range
Terminal window
# Setup detectors for all indexes
opensearch-mgr anomaly-setup
# Setup for specific index
opensearch-mgr anomaly-setup --index payment_queries
# Force recreate (if already exists)
opensearch-mgr anomaly-setup --force
# Show status and recent anomalies
opensearch-mgr anomaly-status
# List all detectors
opensearch-mgr anomaly-list
# View anomaly results
opensearch-mgr anomaly-results payment-latency-detector
opensearch-mgr anomaly-results --all
opensearch-mgr anomaly-results --all -t 0.5 # Grade >= 0.5 only
# Start/stop detectors
opensearch-mgr anomaly-start --all
opensearch-mgr anomaly-stop payment-latency-detector
# Delete detectors
opensearch-mgr anomaly-delete --all --force
Terminal window
# 1. Generate 24h of data with built-in anomalies
node /root/opensearch/scripts/generate-anomaly-demo-logs.js --hours 24 --ingest
# 2. Setup detectors
opensearch-mgr anomaly-setup
# 3. Wait 2-3 minutes for detector initialization
# 4. Check status
opensearch-mgr anomaly-status
# 5. View detected anomalies
opensearch-mgr anomaly-results --all -t 0.3
TimeDurationDescription
3:00 AM15 minSpike — DB connection pool exhausted
9:00 AM30 minGradual rise — morning traffic surge
2:00 PM10 minExtreme spike — external API timeout
8:00 PM45 minSustained high — background job contention

Detector shows INIT_FAILURE:

  • Ensure target index has data (minimum ~30 data points)
  • Verify timestamp field format: yyyy-MM-dd HH:mm:ss
  • Check OpenSearch logs: opensearch-mgr logs opensearch

No anomalies detected after setup:

  • Wait 2-3 minutes — detectors need a learning period
  • Run: opensearch-mgr anomaly-results --all -t 0 to see all results including low-grade
  • Try historical analysis on existing data

Detector won’t start:

  • Verify plugin is installed: curl localhost:9200/_cat/plugins | grep anomaly