---
title: ES|QL TOP function
description: 
url: https://www.elastic.co/docs/reference/query-languages/esql/functions-operators/aggregation-functions/top
products:
  - Elasticsearch
---

# ES|QL TOP function
## Syntax

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


## Parameters

<definitions>
  <definition term="field">
    The field to collect the top values for.
  </definition>
  <definition term="limit">
    The maximum number of values to collect.
  </definition>
  <definition term="order">
    The order to calculate the top values. Either `asc` or `desc`, and defaults to `asc` if omitted.
  </definition>
  <definition term="outputField">
    The extra field that, if present, will be the output of the TOP call instead of `field`.<applies-to>Elastic Stack: Generally available since 9.3</applies-to>
  </definition>
</definitions>


## Description

Collects the top values for a field. Includes repeated values.

## Supported types


| field   | limit   | order   | outputField | result  |
|---------|---------|---------|-------------|---------|
| boolean | integer | keyword |             | boolean |
| boolean | integer |         |             | boolean |
| date    | integer | keyword | date        | date    |
| date    | integer | keyword | double      | double  |
| date    | integer | keyword | integer     | integer |
| date    | integer | keyword | long        | long    |
| date    | integer | keyword |             | date    |
| date    | integer |         |             | date    |
| double  | integer | keyword | date        | date    |
| double  | integer | keyword | double      | double  |
| double  | integer | keyword | integer     | integer |
| double  | integer | keyword | long        | long    |
| double  | integer | keyword |             | double  |
| double  | integer |         |             | double  |
| integer | integer | keyword | date        | date    |
| integer | integer | keyword | double      | double  |
| integer | integer | keyword | integer     | integer |
| integer | integer | keyword | long        | long    |
| integer | integer | keyword |             | integer |
| integer | integer |         |             | integer |
| ip      | integer | keyword |             | ip      |
| ip      | integer |         |             | ip      |
| keyword | integer | keyword |             | keyword |
| keyword | integer |         |             | keyword |
| long    | integer | keyword | date        | date    |
| long    | integer | keyword | double      | double  |
| long    | integer | keyword | integer     | integer |
| long    | integer | keyword | long        | long    |
| long    | integer | keyword |             | long    |
| long    | integer |         |             | long    |
| text    | integer | keyword |             | keyword |
| text    | integer |         |             | keyword |


## Example

```esql
FROM employees
| STATS top_salaries = TOP(salary, 3, "desc"), top_salary = MAX(salary)
```


| top_salaries:integer  | top_salary:integer |
|-----------------------|--------------------|
| [74999, 74970, 74572] | 74999              |