{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "title": "Avg duration per method/status_code",
  "data": {
    "url": {
      "%context%": true,
      "%timefield%": "@timestamp",
      "index": "logs-*",
      "body": {
        "size": 0,
        "aggs": {
          "combo": {
            "composite": {
              "size": 2000,
              "sources": [
                { "status_code": { "terms": { "field": "status_code" } } },
                { "method": { "terms": { "field": "method" } } }
              ]
            },
            "aggs": {
              "avg_duration": { "avg": { "field": "duration_ms" } }
            }
          }
        }
      }
    },
    "format": { "property": "aggregations.combo.buckets" }
  },
  "mark": "rect",
  "encoding": {
    "x": {
      "field": "key.method",
      "type": "nominal",
      "title": "Method"
    },
    "y": {
      "field": "key.status_code",
      "type": "ordinal",
      "title": "Status code"
    },
    "color": {
      "field": "avg_duration.value",
      "type": "quantitative",
      "title": "Avg duration (ms)",
      "scale": { "scheme": "reds" }
    },
    "tooltip": [
      { "field": "key.method", "title": "Method" },
      { "field": "key.status_code", "title": "Status" },
      { "field": "avg_duration.value", "title": "Avg duration (ms)" }
    ]
  }
}
