Visualizing an elasticseach query over jaeger span data

I’m trying to work out how best to visualise some data that we collect from jaeger tracing that is stored in an Elasticsearch repository.

I have a query that will work out the average time it takes for a process to complete from the start of one span to the end of another span. However, I am having trouble mapping the query to the inputs required in Grafana. Specifically, it’s the second aggregation that I have, the one called max_endTimeMicro

My entire elasticsearch query is here. Are there resources that someone could point me to that might help me resolve this? I haven’t been able to find anything to help so far

{
  "size": 0,
  "aggs": {
    "group_by_traceID": {
      "terms": {
        "field": "traceID"
      },
      "aggs": {
        "min_startTimeMicro": {
          "min": {
            "field": "startTime"
          }
        },
        "max_endTimeMicro": {
          "filter" : { "term": { "operationName": "UpdateRecordWorker" } },
          "aggs": {
            "max_end_time_micro": {
              "max": { 
                "script": {
                  "lang": "painless",
                  "source": "doc['startTime'].value + doc['duration'].value"
                }
              }
            }
          }
        },
        "duration_to_active": {
          "bucket_script": {
            "buckets_path":{
              "start_time": "min_startTimeMicro",
              "end_time": "max_endTimeMicro>max_end_time_micro"
            },
            "script": {
              "lang": "painless",
              "source": "params.end_time - params.start_time"
            }
          }
        }
      }
    },
    "trace_stats": {
      "avg_bucket": {
        "buckets_path": "group_by_traceID>duration_to_active"
      }
    }
  }
}