Anyone knows how to query in the script to bucket the counts into seconds. because in kibana if we filter timestamp of the count by seconds it will automatically scale to 5 seconds.
In Lens there's an easy way to do this - it's called "Normalize per unit" in the "advanced options":
It will show the count in the chart scaled per second no matter the underlying date histogram interval.
Is this a Kibana related question? If you are building raw Elasticsearch queries and use them outside of Kibana, it's probably better to ask this question in the Elasticsearch forum instead.
On this level, the
rate aggregation is probably what you are looking for: Rate aggregation | Elasticsearch Guide [7.13] | Elastic