Scripted Aggreations

I have documents with 3 fields: queue_time, start_time, end_time. I want to operate on the wait_time which is the start_time - queue_time. I know I can use a script query to search for document with described wait_times. Can I also do aggregations based on a script? Say count documents with wait_time > 3600 secs or build a histogram base on wait_time? I'm aware I can just reindex and add a wait_time field, so please don't suggest it. Reindexing can be easy, but modifying new documents is not in my case.