Type to search.

Query case data with ES|QL

Serverless

Elastic Cloud Serverless projects are autoscaled environments, fully managed by Elastic and available on Elastic Cloud.

Availability

  • Generally available

    This functionality is generally available and ready for production usage.

Serverless interfaces and procedures might differ from classic Elastic Stack deployments.

Stack GA 9.5+ …

The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats.

Availability

  • Generally available since 9.5

    This functionality is generally available and ready for production usage.

  • Preview from 9.2 to 9.4

    This functionality is in technical preview and is ready for evaluation. Use with caution in production; it is not recommended for mission-critical workloads. Elastic will work to fix any issues, but features in technical preview are not subject to the support SLA of official GA features. Specific Support terms apply.

Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments.

This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.

ES|QL queries the analytics indices directly, which is ideal for calculating metrics like case volume, closure rates, and mean time to respond (MTTR). This page provides sample queries you can adapt in ES|QL in Discover.

Query the shared .cases, .cases-activity, and .cases-attachments indices, and reference fields with the singular case.* prefix, such as case.status. For field units and other details, refer to the field reference. Here are some sample queries to get you started:

  • Count open cases by severity:

    ES|QL
    FROM .cases
    | WHERE case.status == "open"
    | STATS case_count = COUNT(*) BY case.severity
    | SORT case_count DESC
    
  • Find mean time to resolve by severity:

    ES|QL
    FROM .cases
    | WHERE case.status == "closed" AND case.time_to_resolve IS NOT NULL
    | STATS mttr_seconds = AVG(case.time_to_resolve) BY case.severity
    | EVAL mttr_hours = ROUND(mttr_seconds / 3600, 1)
    | SORT mttr_seconds DESC
    
  • Count open cases by solution (owner):

    ES|QL
    FROM .cases
    | WHERE case.status == "open"
    | STATS case_count = COUNT(*) BY owner
    | SORT case_count DESC
    
  • Join activity to current case attributes:

    ES|QL
    FROM .cases-activity
    | STATS actions = COUNT(*) BY case.id
    | LOOKUP JOIN .cases ON case.id
    | KEEP case.id, case.title, case.status, actions
    

Each index covers one solution in one space, so use the index name for the data you want, such as .internal.cases.observability-default. Reference fields without the case.* prefix, such as status instead of case.status. These examples use the default space. Here are some sample queries to get you started:

  • Count cases by status. Change the index name to target a different solution or space:

    ES|QL
    FROM .internal.cases.observability-default
    | STATS count = COUNT(*) BY status
    
  • Find open Security cases, with the most recent first:

    ES|QL
    FROM .internal.cases.securitysolution-default
    | WHERE status == "open"
    | SORT created_at DESC
    
  • Find the average time to close Security cases:

    ES|QL
    FROM .internal.cases.securitysolution-default
    | STATS average_time_to_close = AVG(time_to_resolve)