How to create OpenSearch query to calculate error rate and trigger condition

I tried creating OpenSearch query to calculate error rate for setting up alerts.

What I'm trying to do is calculate count of @message : "Error" / count of @timestamp * 100. but it is not working as the @timestamp count is considered as Object rather than number.

Here is my code :

GET Data/_search
{
   "size": 0,
   "query": {
      "bool": {
         "must": [{
           "match": {
             "@message": "Error"
           }
         }],
         "filter": [],
         "should": [],
         "must_not": []
      }
   },
  "aggs": {
    "month": {
      "date_histogram": {
        "field": "@timestamp",
        "interval": "10m"
      },
      "aggs": {
        "@timestamp": {
         "terms": {
            "field": "@timestamp",
            "order": {
               "_count": "desc"
            }
         }
      },
        "@message": {
         "terms": {
            "field": "@message.keyword",
            "order": {
               "_count": "desc"
            }
         }
      },
        "rate": {
          "bucket_script": {
            "buckets_path": {
              "timestamp_count": "@timestamp._count",
              "error_count": "@message._count"
            },
            "script": "params.error_count / params.timestamp_count * 100"
          }
        }
      }
    }
  }
}

Any help would be appreciated.

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum