ArangoDB v2.8 reached End of Life (EOL) and is no longer supported.
This documentation is outdated. Please see the most recent version here: Try latest
Working with Indexes using HTTP
Read index
returns an index
GET /_api/index/{index-handle}
Path Parameters
- index-handle (required): The index-handle.
The result is an object describing the index. It has at least the following attributes: - id: the identifier of the index
-
type: the index type
All other attributes are type-dependent. For example, some indexes provide unique or sparse flags, whereas others don’t. Some indexes also provide a selectivity estimate in the selectivityEstimate attribute of the result.
Return codes-
200: If the index exists, then a HTTP 200 is returned.
-
404: If the index does not exist, then a HTTP 404 is returned.
-
Examples
shell> curl --dump - http://localhost:8529/_api/index/products/0
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
{
"id" : "products/0",
"type" : "primary",
"fields" : [
"_key"
],
"selectivityEstimate" : 1,
"unique" : true,
"sparse" : false,
"error" : false,
"code" : 200
}
shell> curl --dump - http://localhost:8529/_api/index/products/0
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
Create index
creates an index
POST /_api/index#general
Query Parameters
- collection (required): The collection name.
Request Body (json)
NOTE Swagger examples won’t work due to the anchor.
Creates a new index in the collection collection. Expects
an object containing the index details.
The type of the index to be created must specified in the type
attribute of the index details. Depending on the index type, additional
other attributes may need to specified in the request in order to create
the index.
Most indexes (a notable exception being the cap constraint) require the
array of attributes to be indexed in the fields attribute of the index
details. Depending on the index type, a single attribute or multiple
attributes can be indexed.
Indexing system attributes such as _id, _key, _from, and _to
is not supported for user-defined indexes. Manually creating an index using
any of these attributes will fail with an error.
Some indexes can be created as unique or non-unique variants. Uniqueness
can be controlled for most indexes by specifying the unique flag in the
index details. Setting it to true will create a unique index.
Setting it to false or omitting the unique attribute will
create a non-unique index.
Note: The following index types do not support uniqueness, and using
the unique attribute with these types may lead to an error:
- cap constraints
-
fulltext indexes
Note: Unique indexes on non-shard keys are not supported in a cluster.
Hash and skiplist indexes can optionally be created in a sparse variant. A sparse index will be created if the sparse attribute in the index details is set to true. Sparse indexes do not index documents for which any of the index attributes is either not set or is null.
Return codes-
200: If the index already exists, then an HTTP 200 is returned.
-
201: If the index does not already exist and could be created, then an HTTP 201 is returned.
-
400: If an invalid index description is posted or attributes are used that the target index will not support, then an HTTP 400 is returned.
-
404: If collection is unknown, then an HTTP 404 is returned.
-
Delete index
deletes an index
DELETE /_api/index/{index-handle}
Path Parameters
-
index-handle (required): The index handle.
Deletes an index with index-handle.
Return codes -
200: If the index could be deleted, then an HTTP 200 is returned.
-
404: If the index-handle is unknown, then an HTTP 404 is returned.
Examples
shell> curl -X DELETE --dump - http://localhost:8529/_api/index/products/783370369
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
{
"id" : "products/783370369",
"error" : false,
"code" : 200
}
shell> curl -X DELETE --dump - http://localhost:8529/_api/index/products/783370369
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
Read all indexes of a collection
returns all indexes of a collection
GET /_api/index
Query Parameters
-
collection (required): The collection name.
Returns an object with an attribute indexes containing an array of all index descriptions for the given collection. The same information is also available in the identifiers as an object with the index handles as keys.
Return codes -
200: returns a json object containing a list of indexes on that collection.
Examples
Return information about all indexes
shell> curl --dump - http://localhost:8529/_api/index?collection=products
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
{
"indexes" : [
{
"id" : "products/0",
"type" : "primary",
"fields" : [
"_key"
],
"selectivityEstimate" : 1,
"unique" : true,
"sparse" : false
},
{
"id" : "products/778127489",
"type" : "hash",
"fields" : [
"name"
],
"selectivityEstimate" : 1,
"unique" : false,
"sparse" : false
},
{
"id" : "products/778389633",
"type" : "skiplist",
"fields" : [
"price"
],
"unique" : false,
"sparse" : true
}
],
"identifiers" : {
"products/0" : {
"id" : "products/0",
"type" : "primary",
"fields" : [
"_key"
],
"selectivityEstimate" : 1,
"unique" : true,
"sparse" : false
},
"products/778127489" : {
"id" : "products/778127489",
"type" : "hash",
"fields" : [
"name"
],
"selectivityEstimate" : 1,
"unique" : false,
"sparse" : false
},
"products/778389633" : {
"id" : "products/778389633",
"type" : "skiplist",
"fields" : [
"price"
],
"unique" : false,
"sparse" : true
}
},
"error" : false,
"code" : 200
}
shell> curl --dump - http://localhost:8529/_api/index?collection=products
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8