﻿---
title: ES|QL RATE function
description: 
url: https://www.elastic.co/elastic/docs-builder/docs/3028/reference/query-languages/esql/functions-operators/time-series-aggregation-functions/rate
products:
  - Elasticsearch
---

# ES|QL RATE function
<applies-to>
  - Elastic Cloud Serverless: Preview
  - Elastic Stack: Preview since 9.2
</applies-to>


## Syntax

![Embedded](https://www.elastic.co/elastic/docs-builder/docs/3028/reference/query-languages/esql/images/functions/rate.svg)


## Parameters

<definitions>
  <definition term="field">
    the counter field whose per-second average rate of increase is computed
  </definition>
  <definition term="window">
    the time window over which the rate is computed
  </definition>
</definitions>


## Description

Calculates the per-second average rate of increase of a [counter](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/3028/manage-data/data-store/data-streams/time-series-data-stream-tsds#time-series-metric). Rate calculations account for breaks in monotonicity, such as counter resets when a service restarts, and extrapolate values within each bucketed time interval. Rate is the most appropriate aggregate function for counters. It is only allowed in a [STATS](https://www.elastic.co/elastic/docs-builder/docs/3028/reference/query-languages/esql/commands/stats-by) command under a [`TS`](https://www.elastic.co/elastic/docs-builder/docs/3028/reference/query-languages/esql/commands/ts) source command, to be properly applied per time series.

## Supported types


| field           | window                                                                  | result |
|-----------------|-------------------------------------------------------------------------|--------|
| counter_double  | time_duration <applies-to>Elastic Stack: Preview since 9.3</applies-to> | double |
| counter_integer | time_duration <applies-to>Elastic Stack: Preview since 9.3</applies-to> | double |
| counter_long    | time_duration <applies-to>Elastic Stack: Preview since 9.3</applies-to> | double |


## Example

```esql
TS k8s
| STATS max_rate=MAX(RATE(network.total_bytes_in)) BY time_bucket = TBUCKET(5minute)
```


| max_rate: double | time_bucket:date         |
|------------------|--------------------------|
| 64.5             | 2024-05-10T00:20:00.000Z |
| 22.359074        | 2024-05-10T00:15:00.000Z |