How to display elasticsearch "terms" by percent

Hello

  • Grafana 9.4 + Elasticsearch 8.6

I have logs with these properties

  • route → http route (like GET /users/:id
  • http_code > like 404, 200

I want to calcul error_percent by route
error is count(http_code < 300) / count()

I tried with transormations, math queries … nothing helped, I can’t find a way to generate such visualisation.

Ideally I would like to be able to display a table like this

route | ok_percent

GET users/:id | 90%
POST users/:id | 20%

Is there a way of achieving this with Grafana and Elastic?