ArangoDB v3.10 reached End of Life (EOL) and is no longer supported.
This documentation is outdated. Please see the most recent stable version.
Working with geo-spatial indexes
Create a geo-spatial index
Creates a geo-spatial index in the collection collection, if
it does not already exist. Expects an object containing the index details.
Geo indexes are always sparse, meaning that documents that do not contain the index attributes or have non-numeric values in the index attributes will not be indexed.
fields* array of strings
An array with one or two attribute paths.
If it is an array with one attribute path
location, then a geo-spatial index on all documents is created usinglocationas 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, which do not have the attribute path or with value that are not suitable, are ignored.If it is an array with two attribute paths
latitudeandlongitude, then a geo-spatial index on all documents is created usinglatitudeandlongitudeas paths the latitude and the longitude. The values of thelatitudeandlongitudeattributes must each be a number (double). All documents which do not have the attribute paths or which have values that are not suitable are ignored.geoJson boolean
If a geo-spatial index on a
locationis constructed andgeoJsonistrue, then the order within the array is longitude followed by latitude. This corresponds to the format described in http://geojson.org/geojson-spec.html#positionslegacyPolygons boolean
If
geoJsonis set totrue, then this option controls how GeoJSON Polygons are interpreted.- If
legacyPolygonsistrue, the smaller of the two regions defined by a linear ring is interpreted as the interior of the ring and a ring can at most enclose half the Earth’s surface. - If
legacyPolygonsisfalse, the area to the left of the boundary ring’s path is considered to be the interior and a ring can enclose the entire surface of the Earth.
The default is
truefor geo indexes that were created in versions before 3.10, andfalsefor geo indexes created in 3.10 or later.- If
Examples
Creating a geo index with a location attribute
curl -X POST --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/index?collection=products
{
"type": "geo",
"fields": [
"b"
]
}Show output
HTTP/1.1 201 Created
content-type: application/json
cache-control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0, max-age=0, s-maxage=0
connection: Keep-Alive
content-length: 264
content-security-policy: frame-ancestors 'self'; form-action 'self';
expires: 0
pragma: no-cache
server: ArangoDB
strict-transport-security: max-age=31536000 ; includeSubDomains
x-arango-queue-time-seconds: 0.000000
x-content-type-options: nosniff
{
"bestIndexedLevel" : 17,
"fields" : [
"b"
],
"geoJson" : false,
"id" : "products/70941",
"isNewlyCreated" : true,
"legacyPolygons" : false,
"maxNumCoverCells" : 8,
"name" : "idx_1795421227045617665",
"sparse" : true,
"type" : "geo",
"unique" : false,
"worstIndexedLevel" : 4,
"error" : false,
"code" : 201
}Creating a geo index with latitude and longitude attributes
curl -X POST --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/index?collection=products
{
"type": "geo",
"fields": [
"e",
"f"
]
}Show output
HTTP/1.1 201 Created
content-type: application/json
cache-control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0, max-age=0, s-maxage=0
connection: Keep-Alive
content-length: 268
content-security-policy: frame-ancestors 'self'; form-action 'self';
expires: 0
pragma: no-cache
server: ArangoDB
strict-transport-security: max-age=31536000 ; includeSubDomains
x-arango-queue-time-seconds: 0.000000
x-content-type-options: nosniff
{
"bestIndexedLevel" : 17,
"fields" : [
"e",
"f"
],
"geoJson" : false,
"id" : "products/70951",
"isNewlyCreated" : true,
"legacyPolygons" : false,
"maxNumCoverCells" : 8,
"name" : "idx_1795421227060297728",
"sparse" : true,
"type" : "geo",
"unique" : false,
"worstIndexedLevel" : 4,
"error" : false,
"code" : 201
}