Kibana Dashboard - Display difference between two counts

Hi there,

I've been searching on anything new to this issue for the whole weekend now, but I've found only posts which are 3+ years old.

If I needed to do implement my requirement manually, I'd do the following:

GET my-index/_count
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "state.before": 1
          }
        },
        {
          "match": {
            "state.after": 2
          }
        }
      ]
    }
  }
}

This would return a count of, let's say , 10.

Then i would run the following query:

GET my-index/_count
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "state.before": 2
          }
        },
        {
          "match": {
            "state.after": 3
          }
        }
      ]
    }
  }
}

This would return, let's say, 8.

Now I would calculate 10 - 8 = 2. And I would like to display this difference, i.e. the 2, as a number in a Kibana dashboard. Is that possible? And if so, what is the least expensive way in terms of consumption of CPU, RAM, etc.?

Thanks in advance!

Hi @seb.sch

have you tried already a Lens Metric with a formula like this?

count(kql='state.before: 1 AND state.after: 2') - count(kql='state.before: 2 AND state.after: 3')

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.