---
title: "Create geo-spatial index"
method: POST
path: "/_fabric/{fabric}/_api/index/geo"
tags: ["Indexes"]
---

# Create geo-spatial index

`POST /_fabric/{fabric}/_api/index/geo`

## Request

- The document declares no server URL.
- Auth: one of:
  - API key in header `Authorization`
  - HTTP bearer
- TypeScript: <https://skmtc.dev/macrometa/apis/macrometa-api-reference/docs/_fabric/:fabric/_api/index/geo/post.ts> (a function with typed inputs; its response is checked against the schema)

Create a geo index.

**Note**: Geo indexes are always sparse, meaning that documents that do not contain the index attributes or have non-numeric values in the index attributes are not indexed.

## Path parameters

- `fabric` string, string, required

## Query parameters

- `collection` string, required

## Request body

- ApiIndexGeo
  - `fields` string[]: An array with one or two attribute paths. If it is an array with one attribute path *location*, a geo-spatial index on all documents is created using *location* as path to the coordinates. The value of the attribute must be an array with at least two double values. The array must contain the latitude (first value) and the longitude (second value). All documents, that do not have the attribute path or with value that are not suitable, are ignored. If it is an array with two attribute paths *latitude* and *longitude*, a geo-spatial index on all documents is created using *latitude* and *longitude* as paths the latitude and the longitude. The value of the attribute *latitude* and of the attribute *longitude* must a double. Note: All documents, that do not have the attribute paths or which values are not suitable, are ignored. If it is an array with two attribute paths *latitude* and *longitude*, a geo-spatial index on all documents is created using *latitude* and *longitude* as paths the latitude and the longitude. The value of the attribute *latitude* and *longitude* must be a double. All documents that do not have the attribute paths or which values are not suitable are ignored.
  - `geoJson` string: If a geo-spatial index on a *location* is constructed and *geoJson* is *true*, the order within the array is longitude followed by latitude. This corresponds to the format described in http://geojson.org/geojson-spec.html#positions.
  - `type` string, required: Must be equal to *"geo"*.

## Response `200`

Successfully fetched existing geo index.

- ApiIndexPostGeoHttpExamplesRc200
  - `code` integer: HTTP response code.
  - `error` boolean: Flag if there is an error in response. *False* for this response.
  - `geoJson` boolean: If a geo-spatial index on a *location* is constructed and *geoJson* is *true*, the order within the array is longitude followed by latitude. This corresponds to the format described in http://geojson.org/geojson-spec.html#positions.
  - `fields` string[]: HTTP response code.
  - `maxNumCoverCells` integer: The maximum number of cover cells.
  - `worstIndexedLevel` integer: The worst indexed level.
  - `id` string: Index identifier.
  - `name` string: Name of the index.
  - `selectivityEstimate` number: The selectivity estimate of index.
  - `sparse` boolean: *True* if index is sparse type.
  - `type` string: Index type.
  - `unique` boolean: *True* if index is unique.

## Other responses

- `201`: Successfully created geo index.
- `400`: Failed due to missing or malformed data. Verify that all parameters are complete.
- `403`: Failed because you do not have access to the server.
- `404`: Failed to find specified collection.

---

[API](https://skmtc.dev/macrometa/apis/macrometa-api-reference.md) - [All operations](https://skmtc.dev/macrometa/apis/macrometa-api-reference/llms.txt) - [OpenAPI document](https://skmtc.dev/macrometa/apis/macrometa-api-reference/revisions/2006b6d7f31d?raw)
