# GEOSEARCH

```json metadata
{
  "schema_version": 2,
  "title": "GEOSEARCH",
  "description": "Queries a geospatial index for members inside an area of a box or a circle.",
  "categories": ["docs","develop","stack","oss","rs","rc","oss","kubernetes","clients"],
  "arguments": [{"display_text":"key","key_spec_index":0,"name":"key","type":"key"},{"arguments":[{"display_text":"member","name":"member","token":"FROMMEMBER","type":"string"},{"arguments":[{"display_text":"longitude","name":"longitude","type":"double"},{"display_text":"latitude","name":"latitude","type":"double"}],"name":"fromlonlat","token":"FROMLONLAT","type":"block"}],"name":"from","type":"oneof"},{"arguments":[{"arguments":[{"display_text":"radius","name":"radius","token":"BYRADIUS","type":"double"},{"arguments":[{"display_text":"m","name":"m","token":"M","type":"pure-token"},{"display_text":"km","name":"km","token":"KM","type":"pure-token"},{"display_text":"ft","name":"ft","token":"FT","type":"pure-token"},{"display_text":"mi","name":"mi","token":"MI","type":"pure-token"}],"name":"unit","type":"oneof"}],"name":"circle","type":"block"},{"arguments":[{"display_text":"width","name":"width","token":"BYBOX","type":"double"},{"display_text":"height","name":"height","type":"double"},{"arguments":[{"display_text":"m","name":"m","token":"M","type":"pure-token"},{"display_text":"km","name":"km","token":"KM","type":"pure-token"},{"display_text":"ft","name":"ft","token":"FT","type":"pure-token"},{"display_text":"mi","name":"mi","token":"MI","type":"pure-token"}],"name":"unit","type":"oneof"}],"name":"box","type":"block"}],"name":"by","type":"oneof"},{"arguments":[{"display_text":"asc","name":"asc","token":"ASC","type":"pure-token"},{"display_text":"desc","name":"desc","token":"DESC","type":"pure-token"}],"name":"order","optional":true,"type":"oneof"},{"arguments":[{"display_text":"count","name":"count","token":"COUNT","type":"integer"},{"display_text":"any","name":"any","optional":true,"token":"ANY","type":"pure-token"}],"name":"count-block","optional":true,"type":"block"},{"display_text":"withcoord","name":"withcoord","optional":true,"token":"WITHCOORD","type":"pure-token"},{"display_text":"withdist","name":"withdist","optional":true,"token":"WITHDIST","type":"pure-token"},{"display_text":"withhash","name":"withhash","optional":true,"token":"WITHHASH","type":"pure-token"}],
  "syntax_fmt": "GEOSEARCH key \u003cFROMMEMBER member | FROMLONLAT longitude latitude\u003e\n  \u003cBYRADIUS radius \u003cM | KM | FT | MI\u003e | BYBOX width height \u003cM | KM |\n  FT | MI\u003e\u003e [ASC | DESC] [COUNT count [ANY]] [WITHCOORD] [WITHDIST]\n  [WITHHASH]",
  "complexity": "O(N+log(M)) where N is the number of elements in the grid-aligned bounding box area around the shape provided as the filter and M is the number of items inside the shape",
  "group": "geo",
  "command_flags": ["readonly"],
  "acl_categories": ["@read","@geo","@slow"],
  "since": "6.2.0",
  "arity": -7,
  "key_specs": [{"RO":true,"access":true,"begin_search":{"spec":{"index":1},"type":"index"},"find_keys":{"spec":{"keystep":1,"lastkey":0,"limit":0},"type":"range"}}],
  "tableOfContents": {"sections":[{"id":"required-arguments","title":"Required arguments"},{"id":"optional-arguments","title":"Optional arguments"},{"id":"examples","title":"Examples"},{"id":"redis-software-and-redis-cloud-compatibility","title":"Redis Software and Redis Cloud compatibility"},{"id":"return-information","title":"Return information"}]}

,
  "codeExamples": []
}
```

Return the members of a sorted set populated with geospatial information using [`GEOADD`](https://redis.io/docs/latest/commands/geoadd), which are within the borders of the area specified by a given shape. This command extends the [`GEORADIUS`](https://redis.io/docs/latest/commands/georadius) command, so in addition to searching within circular areas, it supports searching within rectangular areas.

This command should be used in place of the deprecated [`GEORADIUS`](https://redis.io/docs/latest/commands/georadius) and [`GEORADIUSBYMEMBER`](https://redis.io/docs/latest/commands/georadiusbymember) commands.

## Required arguments

<details open><summary><code>key</code></summary>

The name of the key that holds the geospatial index (a sorted set).

</details>

Query center point options:

<details open><summary><code>FROMMEMBER member</code></summary>

Use the position of the existing `member` as the center of the search. Mutually exclusive with `FROMLONLAT`.

</details>

<details open><summary><code>FROMLONLAT longitude latitude</code></summary>

Use the given coordinates as the center of the search. Mutually exclusive with `FROMMEMBER`.

</details>

Query shape options:

<details open><summary><code>BYRADIUS radius M | KM | FT | MI</code></summary>

Search within a circle of the given `radius` in the specified unit. Mutually exclusive with `BYBOX`.

</details>

<details open><summary><code>BYBOX width height M | KM | FT | MI</code></summary>

Search within an axis-aligned box of the given `width` and `height` in the specified unit. Mutually exclusive with `BYRADIUS`.

</details>

## Optional arguments

<details open><summary><code>ASC | DESC</code></summary>

Sort the results by distance from the center: nearest first (`ASC`) or farthest first (`DESC`).

</details>

<details open><summary><code>COUNT count [ANY]</code></summary>

Return at most `count` matches. With `ANY`, the command returns as soon as enough matches are found — faster, but the results may be unsorted. Without `COUNT`, all matching items are returned.
This means that the results returned may not be the ones closest to the specified point, but the effort invested by the server to generate them is significantly less. When ANY is not provided, the command will perform an effort that is proportional to the number of items matching the specified area and sort them, so to query very large areas with a very small COUNT option may be slow even if just a few results are returned.

</details>

<details open><summary><code>WITHCOORD</code></summary>

Also return the longitude and latitude of each matching item.

</details>

<details open><summary><code>WITHDIST</code></summary>

Also return the distance of each matching item from the center, in the same unit as the radius.

</details>

<details open><summary><code>WITHHASH</code></summary>

Also return the raw 52-bit geohash-encoded score of each matching item.

</details>

## Examples


redis> GEOADD Sicily 13.361389 38.115556 "Palermo" 15.087269 37.502669 "Catania"
(integer) 2
redis> GEOADD Sicily 12.758489 38.788135 "edge1"   17.241510 38.788135 "edge2"
(integer) 2
redis> GEOSEARCH Sicily FROMLONLAT 15 37 BYRADIUS 200 km ASC
1) "Catania"
2) "Palermo"
redis> GEOSEARCH Sicily FROMLONLAT 15 37 BYBOX 400 400 km ASC WITHCOORD WITHDIST
1) 1) "Catania"
   2) "56.4413"
   3) 1) "15.087267458438873"
      2) "37.50266842333162"
2) 1) "Palermo"
   2) "190.4424"
   3) 1) "13.361389338970184"
      2) "38.1155563954963"
3) 1) "edge2"
   2) "279.7403"
   3) 1) "17.241510450839996"
      2) "38.78813451624225"
4) 1) "edge1"
   2) "279.7405"
   3) 1) "12.75848776102066"
      2) "38.78813451624225"


## Redis Software and Redis Cloud compatibility

| Redis<br />Software | Redis<br />Cloud | <span style="min-width: 9em; display: table-cell">Notes</span> |
|:----------------------|:-----------------|:------|
| <span title="Supported">&#x2705; Standard</span><br /><span title="Supported"><nobr>&#x2705; Active-Active</nobr></span> | <span title="Supported">&#x2705; Standard</span><br /><span title="Supported"><nobr>&#x2705; Active-Active</nobr></span> |  |

## Return information

**RESP2:**

One of the following:
* If no `WITH*` option is specified, an [Array reply](../../develop/reference/protocol-spec#arrays) of matched member names
* If `WITHCOORD`, `WITHDIST`, or `WITHHASH` options are specified, the command returns an [Array reply](../../develop/reference/protocol-spec#arrays) of arrays, where each sub-array represents a single item:
    * The distance from the center as a floating point number, in the same unit specified in the radius.
    * The Geohash integer.
    * The coordinates as a two items x,y array (longitude,latitude).

**RESP3:**

One of the following:
* If no `WITH*` option is specified, an [Array reply](../../develop/reference/protocol-spec#arrays) of matched member names
* If `WITHCOORD`, `WITHDIST`, or `WITHHASH` options are specified, the command returns an [Array reply](../../develop/reference/protocol-spec#arrays) of arrays, where each sub-array represents a single item:
    * The distance from the center as a floating point number, in the same unit specified in the radius.
    * The Geohash integer.
    * The coordinates as a two items x,y array (longitude,latitude).



