﻿---
title: ES|QL ST_GEOTILE function
description: 
url: https://www.elastic.co/elastic/docs-builder/docs/3016/reference/query-languages/esql/functions-operators/spatial-functions/st_geotile
products:
  - Elasticsearch
---

# ES|QL ST_GEOTILE 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/3016/reference/query-languages/esql/images/functions/st_geotile.svg)


## Parameters

<definitions>
  <definition term="geometry">
    Expression of type `geo_point`. If `null`, the function returns `null`.
  </definition>
  <definition term="precision">
    Expression of type `integer`. If `null`, the function returns `null`. Valid values are between [0 and 29](https://wiki.openstreetmap.org/wiki/Zoom_levels).
  </definition>
  <definition term="bounds">
    Optional bounds to filter the grid tiles, a `geo_shape` of type `BBOX`. Use [`ST_ENVELOPE`](https://www.elastic.co/elastic/docs-builder/docs/3016/reference/query-languages/esql/functions-operators/spatial-functions/st_envelope) if the `geo_shape` is of any other type.
  </definition>
</definitions>


## Description

Calculates the `geotile` of the supplied geo_point at the specified precision. The result is long encoded. Use [`TO_STRING`](https://www.elastic.co/elastic/docs-builder/docs/3016/reference/query-languages/esql/functions-operators/type-conversion-functions/to_string) to convert the result to a string, [`TO_LONG`](https://www.elastic.co/elastic/docs-builder/docs/3016/reference/query-languages/esql/functions-operators/type-conversion-functions/to_long) to convert it to a `long`, or [`TO_GEOSHAPE`](https://www.elastic.co/elastic/docs-builder/docs/3016/reference/query-languages/esql/functions-operators/type-conversion-functions/to_geoshape) to calculate the `geo_shape` bounding geometry.  These functions are related to the [`geo_grid` query](https://www.elastic.co/elastic/docs-builder/docs/3016/reference/query-languages/query-dsl/query-dsl-geo-grid-query) and the [`geotile_grid` aggregation](https://www.elastic.co/elastic/docs-builder/docs/3016/reference/aggregations/search-aggregations-bucket-geotilegrid-aggregation).

## Supported types


| geometry  | precision | bounds    | result  |
|-----------|-----------|-----------|---------|
| geo_point | integer   | geo_shape | geotile |
| geo_point | integer   |           | geotile |


## Example

```esql
FROM airports
| EVAL geotile = ST_GEOTILE(location, 2)
| STATS
    count = COUNT(geotile),
    centroid = ST_CENTROID_AGG(location)
      BY geotile
| EVAL geotileString = TO_STRING(geotile)
| SORT count DESC, geotileString ASC
| KEEP count, centroid, geotileString
```


| count:long | centroid:geo_point                              | geotileString:keyword |
|------------|-------------------------------------------------|-----------------------|
| 286        | POINT (39.31202001609169 35.149993664386415)    | 2/2/1                 |
| 197        | POINT (-55.387361375756825 31.952955322292855)  | 2/1/1                 |
| 136        | POINT (-110.97162496141048 36.87185255084734)   | 2/0/1                 |
| 106        | POINT (119.35907618669827 25.46263281488791)    | 2/3/1                 |
| 67         | POINT (-58.031108492373754 -22.624166105151065) | 2/1/2                 |
| 46         | POINT (142.95455511274707 -20.581492295427978)  | 2/3/2                 |
| 34         | POINT (31.38476753634784 -14.64374022804858)    | 2/2/2                 |
| 8          | POINT (-160.0723083713092 -19.124013530672528)  | 2/0/2                 |
| 6          | POINT (23.95813101902604 70.17537698848173)     | 2/2/0                 |
| 3          | POINT (-133.4001641627401 72.06833167467266)    | 2/0/0                 |
| 2          | POINT (-68.47209956031293 66.77569948369637)    | 2/1/0                 |