ArangoDB v3.12 is under development and not released yet.
This documentation is not final and potentially incomplete.
Working with geo-spatial indexes
Create a geo-spatial index
POST /_api/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.
Query Parameters
- collection (string, required): The collection name.
Request Body
-
type (string, required): must be equal to
"geo"
. -
name (string, optional): An easy-to-remember name for the index to look it up or refer to it in index hints. Index names are subject to the same character restrictions as collection names. If omitted, a name is auto-generated so that it is unique with respect to the collection, e.g.
idx_832910498
. -
fields (array of strings, required): 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 usinglocation
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, 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
latitude
andlongitude
, then a geo-spatial index on all documents is created usinglatitude
andlongitude
as paths the latitude and the longitude. The values of thelatitude
andlongitude
attributes 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, optional): If a geo-spatial index on a
location
is constructed andgeoJson
istrue
, then the order within the array is longitude followed by latitude. This corresponds to the format described in http://geojson.org/geojson-spec.html#positions -
legacyPolygons (boolean, optional): If
geoJson
is set totrue
, then this option controls how GeoJSON Polygons are interpreted.- If
legacyPolygons
istrue
, 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
legacyPolygons
isfalse
, 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
true
for geo indexes that were created in versions before 3.10, andfalse
for geo indexes created in 3.10 or later. - If
-
inBackground (boolean, optional): You can set this option to
true
to create the index in the background, which will not write-lock the underlying collection for as long as if the index is built in the foreground. The default value isfalse
.
Responses
HTTP 200: If the index already exists, then a HTTP 200 is returned.
HTTP 201: If the index does not already exist and could be created, then a HTTP 201 is returned.
HTTP 404: If the collection
is unknown, then a HTTP 404 is returned.
Examples
Creating a geo index with a location attribute
shell> curl -X POST --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/index?collection=products <<EOF
{
"type" : "geo",
"fields" : [
"b"
]
}
EOF
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
Creating a geo index with latitude and longitude attributes
shell> curl -X POST --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/index?collection=products <<EOF
{
"type" : "geo",
"fields" : [
"e",
"f"
]
}
EOF
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