This is an introduction to ArangoDB's Http interface for indexes in general. There are special sections for various index types.
Index: Indexes are used to allow fast access to documents. For each collection there is always the primary index which is a hash index for the document identifier.
Index Handle: An index handle uniquely identifies an index in the database. It is a string and consists of a collection identifier and a index identifier separated by /
.
Geo Index: A geo index is used to find places on the surface of the earth fast.
Hash Index: A hash index is used to find documents based on examples.
Skiplist Index: A skiplist is used to find ranges of documents.
Priority Queue: A priority queue based on an attribute of the documents.
The basic operations (create, read, update, delete) for documents are mapped to the standard HTTP methods (POST, GET, PUT, DELETE).
All indexes in ArangoDB have an unique handle. This index handle identifies an index and is managed by ArangoDB. All indexes are found under the URI
http://server:port/_api/index/index-handle
For example: Assume that the index handle is 7254820/63563528
then the URL of that index is:
http://localhost:8529/_api/index/7254820/63563528
GET /_api/index/index-handle
The result is an objects describing the index. It has at least the following attributes:
id
: The identifier of the collection.type
: The type of the collection.All other attributes are type-dependent.
Examples
> curl -X GET --dump - http://localhost:8529/_api/index/117843216/0 HTTP/1.1 200 OK content-type: application/json { "code": 200, "fields": [ "_id" ], "id": "117843216/0", "type": "primary", "error": false }
POST /_api/index?collection=collection-identifier
Creates a new index in the collection collection-identifier. Expects an object containing the index details.
See Accessing Cap Constraints via Http, Accessing Geo Indexes via Http, Accessing Hash Indexes via Http, and Accessing Skip-List Indexes via Http for details. By default, non-unique indexes will be created. To change this, use the unique
attribute in the index details and set its value to true
.
If the index does not already exists and could be created, then a HTTP 201
is returned. If the index already exists, then a HTTP 200
is returned.
If the collection-identifier is unknown, then a HTTP 404
is returned. It is possible to specify a name instead of an identifier.
Examples
Creating an unique constraint:
> curl --data @- -X POST --dump - http://localhost:8529/_api/index?collection=102901008 { "type" : "hash", "unique" : true, "fields" : [ "a", "b" ] } HTTP/1.1 201 Created content-type: application/json { "code": 201, "fields": [ "a", "b" ], "id": "102901008/168054969", "type": "hash", "isNewlyCreated": true, "unique": true, "error": false }
Creating a hash index:
> curl --data @- -X POST --dump - http://localhost:8529/_api/index?collection=105981200 { "type" : "hash", "unique" : false, "fields" : [ "a", "b" ] } HTTP/1.1 201 Created content-type: application/json { "code": 201, "fields": [ "a", "b" ], "id": "105981200/171069625", "type": "hash", "isNewlyCreated": true, "unique": false, "error": false }
Creating a skip-list:
> curl --data @- -X POST --dump - http://localhost:8529/_api/index?collection=109061392 { "type" : "skiplist", "unique" : false, "fields" : [ "a", "b" ] } HTTP/1.1 201 Created content-type: application/json { "code": 201, "fields": [ "a", "b" ], "id": "109061392/173166777", "type": "skiplist", "isNewlyCreated": true, "unique": false, "error": false }
Creating a unique skip-list:
> curl --data @- -X POST --dump - http://localhost:8529/_api/index?collection=112141584 { "type" : "skiplist", "unique" : true, "fields" : [ "a", "b" ] } HTTP/1.1 201 Created content-type: application/json { "code": 201, "fields": [ "a", "b" ], "id": "112141584/175722681", "type": "skiplist", "isNewlyCreated": true, "unique": true, "error": false }
DELETE /_api/index/index-handle
Deletes an index with index-handle.
Examples
> curl -X DELETE --dump - http://localhost:8529/_api/index/180506809/181424313 HTTP/1.1 200 OK content-type: application/json { "code": 200, "id": "180506809/181424313", "error": false }
GET /_api/index?collection=collection-identifier
Returns an object with an attribute indexes
containing a list of all index descriptions for the given collection. The same information is also available in the identifiers
as hash map with the index handle as keys.
Examples
Return information about all indexes:
> curl -X GET --dump - http://localhost:8529/_api/index?collection=115221776 HTTP/1.1 200 OK content-type: application/json { "code": 200, "indexes": [ { "fields": [ "_id" ], "id": "115221776/0", "type": "primary" } ], "error": false, "identifiers": { "115221776/0": { "fields": [ "_id" ], "id": "115221776/0", "type": "primary" } } }