Preview rule alerts generated on specified time range

POST /api/detection_engine/rules/preview

Spaces method and path for this operation:

post /s/{space_id}/api/detection_engine/rules/preview

Refer to Spaces for more information.

Simulates a detection rule using the same rule type and query logic as a persisted rule, over a short time window, without persisting a rule or writing alerts. Use the response to validate queries, see sample matching documents, and inspect execution logs. Pair invocationCount and timeframeEnd to cap run time.

Query parameters

  • enable_logged_requests boolean

    Enables logging and returning in response ES queries, performed during rule execution

application/json

Body object Required

Rule create payload (same shape as POST /api/detection_engine/rules for a given type) plus invocationCount and timeframeEnd to control how the preview is executed. Optional enable_logged_requests surfaces Elasticsearch request logging for debugging.

Any of:

Responses

  • 200 application/json

    Successful response

    Hide response attributes Show response attributes object
    • isAborted boolean
    • logs array[object] Required
      Hide logs attributes Show logs attributes object
      • duration integer Required

        Execution duration in milliseconds

      • errors array[string(nonempty)] Required

        A string that does not contain only whitespace characters

        Minimum length of each is 1.

      • requests array[object]
        Hide requests attributes Show requests attributes object
        • description string(nonempty)

          A string that does not contain only whitespace characters

          Minimum length is 1.

        • duration integer
        • request string(nonempty)

          A string that does not contain only whitespace characters

          Minimum length is 1.

        • request_type string(nonempty)

          A string that does not contain only whitespace characters

          Minimum length is 1.

      • startedAt string(nonempty)

        A string that does not contain only whitespace characters

        Minimum length is 1.

      • warnings array[string(nonempty)] Required

        A string that does not contain only whitespace characters

        Minimum length of each is 1.

    • previewId string(nonempty)

      A string that does not contain only whitespace characters

      Minimum length is 1.

  • 400 application/json

    Invalid input data response

    One of:
  • 401 application/json

    Unsuccessful authentication response

    Hide response attributes Show response attributes object
    • error string Required
    • message string Required
    • statusCode integer Required
  • 500 application/json

    Internal server error response

    Hide response attributes Show response attributes object
    • message string Required
    • status_code integer Required
POST /api/detection_engine/rules/preview
curl \
 --request POST 'https://<KIBANA_URL>/api/detection_engine/rules/preview' \
 --header "Authorization: $API_KEY" \
 --header "Content-Type: application/json" \
 --data '{"description":"Find matching events","from":"now-24h","index":["logs-*"],"invocationCount":1,"language":"kuery","max_signals":20,"name":"Rule preview","query":"process.name : *","risk_score":25,"severity":"low","timeframeEnd":"2025-01-20T12:00:00.000Z","to":"now","type":"query"}'
Request example
{
  "description": "Find matching events",
  "from": "now-24h",
  "index": [
    "logs-*"
  ],
  "invocationCount": 1,
  "language": "kuery",
  "max_signals": 20,
  "name": "Rule preview",
  "query": "process.name : *",
  "risk_score": 25,
  "severity": "low",
  "timeframeEnd": "2025-01-20T12:00:00.000Z",
  "to": "now",
  "type": "query"
}
Response examples (200)
{
  "isAborted": false,
  "logs": [
    {
      "duration": 45,
      "errors": [],
      "requests": [],
      "startedAt": "2025-01-20T10:00:00.000Z",
      "warnings": []
    }
  ],
  "previewId": "7f1c9d1e-4c8a-4a3e-9a5d-0d4f6e1b2a90"
}
Response examples (400)
{
  "error": "Bad Request",
  "message": "[request body].timeframeEnd: expected string, received null",
  "statusCode": 400
}
Response examples (401)
{
  "error": "Unauthorized",
  "message": "[security_exception\n\tRoot causes:\n\t\tsecurity_exception: unable to authenticate user [elastic] for REST request [/_security/_authenticate]]: unable to authenticate user [elastic] for REST request [/_security/_authenticate]",
  "statusCode": 401
}
Response examples (500)
{
  "message": "Internal Server Error",
  "status_code": 500
}