﻿---
title: ES|QL SAMPLE function
description: 
url: https://www.elastic.co/elastic/docs-builder/docs/2866/reference/query-languages/esql/functions-operators/aggregation-functions/sample
products:
  - Elasticsearch
---

# ES|QL SAMPLE function
<applies-to>
  - Elastic Stack: Generally available since 9.1
</applies-to>


## Syntax

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


## Parameters

<definitions>
  <definition term="field">
    The field to collect sample values for.
  </definition>
  <definition term="limit">
    The maximum number of values to collect.
  </definition>
</definitions>


## Description

Collects sample values for a field.

## Supported types


| field           | limit   | result          |
|-----------------|---------|-----------------|
| boolean         | integer | boolean         |
| cartesian_point | integer | cartesian_point |
| cartesian_shape | integer | cartesian_shape |
| date            | integer | date            |
| date_nanos      | integer | date_nanos      |
| double          | integer | double          |
| geo_point       | integer | geo_point       |
| geo_shape       | integer | geo_shape       |
| geohash         | integer | geohash         |
| geohex          | integer | geohex          |
| geotile         | integer | geotile         |
| integer         | integer | integer         |
| ip              | integer | ip              |
| keyword         | integer | keyword         |
| long            | integer | long            |
| text            | integer | keyword         |
| unsigned_long   | integer | unsigned_long   |
| version         | integer | version         |


## Example

```esql
FROM employees
| STATS sample = SAMPLE(gender, 5)
```


| sample:keyword  |
|-----------------|
| [F, M, M, F, M] |