---
title: ES|QL TO_GAUGE function
description: 
url: https://www.elastic.co/docs/reference/query-languages/esql/functions-operators/type-conversion-functions/to_gauge
products:
  - Elasticsearch
---

# ES|QL TO_GAUGE function
<applies-to>
  - Elastic Stack: Planned
</applies-to>


## Syntax

![Embedded](https://www.elastic.co/docs/reference/query-languages/esql/images/generated/x-pack-esql/functions/to_gauge.svg)


## Parameters

<definitions>
  <definition term="field">
    Input value. The input can be a single- or multi-valued column or an expression.
  </definition>
</definitions>


## Description

Converts a counter value to its gauge (plain numeric) equivalent. The output type is determined by the input: `counter_long` converts to `long`, `counter_integer` to `integer`, and `counter_double` to `double`. No values are modified; only the type annotation changes. If the input is already a plain numeric or `aggregate_metric_double`, the function is a no-op. This is useful when a metric field was misclassified as a counter type instead of a plain numeric (gauge) in the index mapping. This function is also available as the `::gauge` cast operator.

## Supported types


| field                   | result                  |
|-------------------------|-------------------------|
| aggregate_metric_double | aggregate_metric_double |
| counter_double          | double                  |
| counter_integer         | integer                 |
| counter_long            | long                    |
| double                  | double                  |
| integer                 | integer                 |
| long                    | long                    |


## Example

```esql
TS k8s
| STATS bytes_in = avg(avg_over_time(network.bytes_in::gauge)) BY cluster, time_bucket = bucket(@timestamp, 10minute)
| EVAL bytes_in = round(bytes_in, 4)
| KEEP bytes_in, cluster, time_bucket
| SORT time_bucket, cluster
| LIMIT 10;
```


| bytes_in:double | cluster:keyword | time_bucket:datetime     |
|-----------------|-----------------|--------------------------|
| 402.05          | prod            | 2024-05-10T00:00:00.000Z |
| 499.9387        | qa              | 2024-05-10T00:00:00.000Z |
| 497.1889        | staging         | 2024-05-10T00:00:00.000Z |
| 552.5219        | prod            | 2024-05-10T00:10:00.000Z |
| 495.0368        | qa              | 2024-05-10T00:10:00.000Z |
| 445.2519        | staging         | 2024-05-10T00:10:00.000Z |
| 718.6667        | prod            | 2024-05-10T00:20:00.000Z |
| 778.8333        | qa              | 2024-05-10T00:20:00.000Z |
| 400.4556        | staging         | 2024-05-10T00:20:00.000Z |
| ;               |                 |                          |

<warning>
  Applying `TO_GAUGE` to a field that is a genuine monotonically increasing counter, rather than a misclassified gauge, will produce raw cumulative counter values instead of gauge samples. Results from aggregations on such values are not meaningful.
</warning>