Grafana to use substraction of two fields in Elasticsearch data source


I have saw articles on ‘How to Add 2 fields in Grafana’ But i would like to know how to subtract 2 values in Grafana. Following is my scenario:

  • I have two fields, called ‘status_codes’ and requests
  • I want to get number of failed requests.
  • My equation is [requests - no of success requests]
  • In the script i wrote something like this _value - doc[’@status_codes.200’].value

BUT the value return in the graph is ‘N/A’

I’m using elasticsearch(7.6.0) and Grafana(6.6.2).

Following is the out file which i’m sending to elasticsearch

    {   "latencies":{


      "Post http://www: dial tcp> socket: too many open files",
      "Post http://www: dial tcp: lookup on dial udp 10.20.30:45: socket: too many open files"




I’d go with something like this:

Thank you @dpotapov. You saved my time.

1 Like

How about serial difference? I have a time series that tracks bytes written (wr) and bytes read (rd) by the containers in my K8s node. These fileds are total count fields. I want to get the serial difference() over a period of time for the wr and rd, like wr[n+1]-wr[n]. How can I do that with the script filed? ES 6.8.10 grafana 6.1.1