# Aggregate events with start and end date

**URL:** <https://discuss.elastic.co/t/aggregate-events-with-start-and-end-date/162371>\
**Category:** Elasticsearch\
**Created:** [December 28, 2018, 5:07pm UTC](https://discuss.elastic.co/t/aggregate-events-with-start-and-end-date/162371 "2018-12-28T17:07:50Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![nmeaux](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nmeaux/32/31380_2.png) [@nmeaux](https://discuss.elastic.co/u/nmeaux)\
**Post date:** [January 31, 2019, 10:11pm UTC](https://discuss.elastic.co/t/aggregate-events-with-start-and-end-date/162371/5 "2019-01-31T22:11:24Z")

</div>

Going ahead on the issue i try to resolv, i found something interesting by using buckets script in this way 🙂

```
         "aggs": {
            "alloccpu": {
                "bucket_script": {
                    "buckets_path": {
                        "jobs1cpu": "jobs1>sum_alloc_cpu",
                        "jobs2cpu": "jobs2>sum_alloc_cpu"
                        "jobs3cpu": "jobs3>sum_alloc_cpu"
                    },
                    "script": {
                        "source": "(params.jobs1cpu+params.jobs2cpu+params.jobs3cpu)"
                    }
                }
            },
            "jobs1": {..},
            "jobs2": {..},
            "jobs3": {..},

```

The problem here, is when i have thousands of jobs i did get something like :

> Caused by: java.lang.IllegalArgumentException: Scripts may be no longer than 16384 characters. The passed in script is 67313 characters. Consider using a plugin if a script longer than this length is a requirement.

I understand with [Scripts may be no longer than 16384 characters - #3 by bfcshop](https://discuss.elastic.co/t/scripts-may-be-no-longer-than-16384-characters/158178/3) , that i may be able to use elasticsearch 6.6 and increase the soft limit.  
But i am looking for something which can be more optimized rather than actually.  
Any ideas ?  
Thx in advance 🙂  
Rgds  
Nicolas

---

_[View the full topic](https://discuss.elastic.co/t/aggregate-events-with-start-and-end-date/162371)._
