﻿---
title: ES|QL CLAMP function
description: 
url: https://www.elastic.co/elastic/docs-builder/docs/2915/reference/query-languages/esql/functions-operators/conditional-functions-and-expressions/clamp
products:
  - Elasticsearch
---

# ES|QL CLAMP function
<applies-to>
  - Elastic Stack: Preview since 9.3
</applies-to>


## Syntax

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


## Parameters

<definitions>
  <definition term="field">
    Numeric expression. If `null`, the function returns `null`.
  </definition>
  <definition term="min">
    The min value to clamp data into.
  </definition>
  <definition term="max">
    The max value to clamp data into.
  </definition>
</definitions>


## Description

Limits (or clamps) the values of all samples to have a lower limit of min and an upper limit of max.

## Supported types


| field         | min           | max           | result        |
|---------------|---------------|---------------|---------------|
| boolean       | boolean       | boolean       | boolean       |
| date          | date          | date          | date          |
| double        | double        | double        | double        |
| double        | integer       | integer       | double        |
| double        | long          | long          | double        |
| double        | unsigned_long | unsigned_long | double        |
| integer       | double        | double        | double        |
| integer       | integer       | integer       | integer       |
| integer       | long          | long          | long          |
| integer       | unsigned_long | unsigned_long | unsigned_long |
| ip            | ip            | ip            | ip            |
| keyword       | keyword       | keyword       | keyword       |
| long          | double        | double        | double        |
| long          | integer       | integer       | long          |
| long          | long          | long          | long          |
| long          | unsigned_long | unsigned_long | unsigned_long |
| unsigned_long | double        | double        | double        |
| unsigned_long | integer       | integer       | unsigned_long |
| unsigned_long | long          | long          | long          |
| unsigned_long | unsigned_long | unsigned_long | unsigned_long |
| version       | version       | version       | version       |


## Example

```esql
TS k8s
| EVAL full_clamped_cost = clamp(network.cost, clamp_max(network.bytes_in, 5), network.bytes_in / 100)
| KEEP full_clamped_cost, @timestamp
```


| full_clamped_cost:double | @timestamp:datetime      |
|--------------------------|--------------------------|
| 10.0                     | 2024-05-10T00:18:33.000Z |
| 9.0                      | 2024-05-10T00:04:49.000Z |
| 9.0                      | 2024-05-10T00:15:51.000Z |
| 9.0                      | 2024-05-10T00:17:12.000Z |
| 9.0                      | 2024-05-10T00:20:46.000Z |