bucket script to find the percent change in filter bucket

I have formed an aggregation query to bucket my tickets based on created_at epoch. Based on my query I will get two buckets each named previous and current.

GET tickets_trend_analysis/_search
{
  "aggs": {
    "time_windows": {
      "filters": {
        "filters": {
          "previous": {
            "range": {
              "created_at": {
                "gte": 1745346660000,
                "lt": 1746037800000
              }
            }
          },
          "current": {
            "range": {
              "created_at": {
                "gte": 1746037800000,
                "lt": 1746728940000
              }
            }
          }
        }
      }
    }
  },
  "size": 0
}

Output

{
  "took": 4,
  "hits": {
    "total": {
      "value": 2951,
      "relation": "eq"
    },
  },
  "aggregations": {
    "time_windows": {
      "buckets": {
        "current": {
          "doc_count": 1905
        },
        "previous": {
          "doc_count": 1046
        }
      }
    }
  }
}```


My ask is, I have to calculate percentage change in these buckets such as ((current - pervious) / previous) * 100 and append the percent change in buckets. How to do that using pipeline aggregation bucket script or is there any other way to do this commutation to find the percent change. My task is to write a trend analysis to compare current set of result with previous set and find the percentage increase/decrease. In this case the percentage change would be ((1905 - 1046) / 1046) * 100 82%. 


I have tired writing bucket_script on my own but I couldn't as I don't completely understand the bucket_script by reading the official document. As per my knowledge the bucket script works on metrics aggs.