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

# ES|QL ST_GEOHASH 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_geohash.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 [1 and 12](https://en.wikipedia.org/wiki/Geohash).
  </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 `geohash` 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 [`geohash_grid` aggregation](https://www.elastic.co/elastic/docs-builder/docs/3016/reference/aggregations/search-aggregations-bucket-geohashgrid-aggregation).

## Supported types


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


## Example

```esql
FROM airports
| EVAL geohash = ST_GEOHASH(location, 1)
| STATS
    count = COUNT(geohash),
    centroid = ST_CENTROID_AGG(location)
      BY geohash
| WHERE count >= 10
| EVAL geohashString = TO_STRING(geohash)
| KEEP count, centroid, geohashString
| SORT count DESC, geohashString ASC
```


| count:long | centroid:geo_point                             | geohashString:keyword |
|------------|------------------------------------------------|-----------------------|
| 118        | POINT (-77.41857436454018 26.96522968734409)   | d                     |
| 96         | POINT (23.181679135886952 27.295384635654045)  | s                     |
| 94         | POINT (70.94076107503807 25.691916451026547)   | t                     |
| 90         | POINT (-104.3941700803116 30.811849871650338)  | 9                     |
| 89         | POINT (18.71573683606942 53.165169130707305)   | u                     |
| 85         | POINT (114.3722876966657 24.908398092505248)   | w                     |
| 51         | POINT (-61.44522591713159 -22.87209844956284)  | 6                     |
| 38         | POINT (-9.429514887252529 25.497624435045413)  | e                     |
| 34         | POINT (-111.8071846965262 52.464381378993174)  | c                     |
| 30         | POINT (28.7045472683385 -14.706001980230212)   | k                     |
| 28         | POINT (159.52750137208827 -25.555616633001982) | r                     |
| 22         | POINT (-4.410395708612421 54.90304926367985)   | g                     |
| 21         | POINT (-69.40534970590046 50.93379438189523)   | f                     |
| 17         | POINT (114.05526293222519 -10.898114638950895) | q                     |
| 16         | POINT (147.40052131412085 21.054660080408212)  | x                     |
| 13         | POINT (63.64716878519035 54.37333276101317)    | v                     |
| 12         | POINT (-39.53510569408536 -11.72166372067295)  | 7                     |