# Scripted Aggreations

**URL:** <https://discuss.elastic.co/t/scripted-aggreations/59358>\
**Category:** Elasticsearch\
**Created:** [August 30, 2016, 8:15pm UTC](https://discuss.elastic.co/t/scripted-aggreations/59358 "2016-08-30T20:15:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gogators](https://avatars.discourse-cdn.com/v4/letter/g/dc4da7/32.png) [@gogators](https://discuss.elastic.co/u/gogators)\
**Post date:** [August 30, 2016, 8:15pm UTC](https://discuss.elastic.co/t/scripted-aggreations/59358/1 "2016-08-30T20:15:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 10:23pm UTC](https://discuss.elastic.co/t/scripted-aggreations/59358/2 "2017-07-05T22:23:53Z")

</div>


