Calculate max parallel elements by time in elasticsearch

I need to calculate max parallel people survey in elastic search. Mapping for this fields are: "start_at": {"type": "date"}, "end_at": {"type": "date"}, So, for one week i need to know with accuracy ~10s when in our system was max people and how much of them :-)

Thx for help :-)

"aggs": { "seconds_histogram": { "date_histogram": { "field": "start_at", "fixed_interval": "1s", "min_doc_count": 0, "extended_bounds": { "min": ..., "max": ... } }, "aggs": { "active_surveys": { "bucket_script": { "buckets_path": { "start": "_key", "end": "_key" }, "script": """ // Survey should have started before or at the bucket second and ended after or at the second. if (doc['start_at'].value.getMillis() <= params.start && doc['end_at'].value.getMillis() >= params.end) { return 1; } else { return 0; } """ } } } }

Back to Top