Aggregate events with start and end date

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

         "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 , 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 :slight_smile:
Rgds
Nicolas