I'm writing a custom code in kibana (vega). In which I want show the the total working hours of employe by calculating diffrence from two available fields like (out time - Intime).
how can I get that in vega by writing a script. (without creating a total count of working hours field in csv file).
{
  "$schema": "https://vega.github.io/schema/vega-lite/v2.json",
  "data": {
    "url": {
      "index": "data2",
      "%context%": true,
      "body": {"size": 10000}
        "aggs": {
        "Working hours": {
            "sum": {
                "script": {
                    "source": "doc['O-time'].value - doc['I-time'].value"
                }
            }
        }
    }
    },
    "format": {"property": "hits.hits"}
  },
  "mark": "bar",
  "encoding": {
    "tooltip": {"field": "_source.ID", "type": "ordinal"},
    "y": {"aggregate":"sum","field": "Working hours", "type": "quantitative"},
    "x": {"field": "_source.NAME", "type": "ordinal"}
  }
}
but using this code I'm able to get names of employe on x-axis but it shows count of working hours as zero/undefined on y axis.
I want the output in this format but here I've used a existing field (total working hours) from the CSV file.


