HTTP Interface for Simple Queries

The Simple Queries API is deprecated from version 3.4.0 on. These endpoints should no longer be used. They are superseded by AQL queries.

Simple Queries

This is an introduction to ArangoDB’s HTTP interface for simple queries.

Simple queries can be used if the query condition is straight forward simple, i.e., a document reference, all documents, a query-by-example, or a simple geo query. In a simple query you can specify exactly one collection and one condition. The result can then be sorted and can be split into pages.

Working with Simples Queries using HTTP

To limit the amount of results to be transferred in one batch, simple queries support a batchSize parameter that can optionally be used to tell the server to limit the number of results to be transferred in one batch to a certain value. If the query has more results than were transferred in one go, more results are waiting on the server so they can be fetched subsequently. If no value for the batchSize parameter is specified, the server will use a reasonable default value.

If the server has more documents than should be returned in a single batch, the server will set the hasMore attribute in the result. It will also return the id of the server-side cursor in the id attribute in the result. This id can be used with the cursor API to fetch any outstanding results from the server and dispose the server-side cursor afterwards.

Return all documents

returns all documents of a collection

PUT /_api/simple/all

This route should no longer be used. All endpoints for Simple Queries are deprecated from version 3.4.0 on. They are superseded by AQL queries.

Request Body (string)

Contains the query.

Returns all documents of a collections. Equivalent to the AQL query FOR doc IN collection RETURN doc. The call expects a JSON object as body with the following attributes:

  • collection: The name of the collection to query.

  • skip: The number of documents to skip in the query (optional).

  • limit: The maximal amount of documents to return. The skip is applied before the limit restriction (optional).

  • batchSize: The number of documents to return in one go. (optional)

  • ttl: The time-to-live for the cursor (in seconds, optional).

  • stream: Create this cursor as a stream query (optional).

Returns a cursor containing the result, see HTTP Cursor for details.

Return codes

  • 201: is returned if the query was executed successfully.

  • 400: is returned if the body does not contain a valid JSON representation of a query. The response body contains an error document in this case.

  • 404: is returned if the collection specified by collection is unknown. The response body contains an error document in this case.

Examples

Limit the amount of documents using limit

shell> curl -X PUT --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/simple/all <<EOF
{ "collection": "products", "skip": 2, "limit" : 2 }
EOF

HTTP/1.1 Created
x-content-type-options: nosniff
content-type: application/json

Show response body

Using a batchSize value

shell> curl -X PUT --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/simple/all <<EOF
{ "collection": "products", "batchSize" : 3 }
EOF

HTTP/1.1 Created
x-content-type-options: nosniff
content-type: application/json

Show response body

Read all document keys

reads all document keys from collection

PUT /_api/simple/all-keys

This route should no longer be used. All endpoints for Simple Queries are deprecated from version 3.4.0 on. They are superseded by AQL queries.

Query Parameters

  • collection (optional): The name of the collection. This parameter is only for an easier migration path from old versions. In ArangoDB versions < 3.0, the URL path was /_api/document and this was passed in via the query parameter “collection”. This combination was removed. The collection name can be passed to /_api/simple/all-keys as body parameter (preferred) or as query parameter.

A JSON object with these properties is required:

  • collection: The collection that should be queried

  • type: The type of the result. The following values are allowed:
  • id: returns an array of document ids (_id attributes)
  • key: returns an array of document keys (_key attributes)
  • path: returns an array of document URI paths. This is the default.

Returns an array of all keys, ids, or URI paths for all documents in the collection identified by collection. The type of the result array is determined by the type attribute.

Note that the results have no defined order and thus the order should not be relied on.

Note: the all-keys simple query is deprecated as of ArangoDB 3.4.0. This API may get removed in future versions of ArangoDB. You can use the /_api/cursor endpoint instead with one of the below AQL queries depending on the desired result:

  • FOR doc IN @@collection RETURN doc._id to mimic type: id
  • FOR doc IN @@collection RETURN doc._key to mimic type: key
  • FOR doc IN @@collection RETURN CONCAT("/_db/", CURRENT_DATABASE(), "/_api/document/", doc._id) to mimic type: path

Return codes

  • 201: All went well.

  • 404: The collection does not exist.

Examples

Return all document paths

shell> curl -X PUT --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/simple/all-keys <<EOF
{ 
  "collection" : "products" 
}
EOF

HTTP/1.1 Created
x-content-type-options: nosniff
content-type: application/json

Show response body

Return all document keys

shell> curl -X PUT --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/simple/all-keys <<EOF
{ 
  "collection" : "products", 
  "type" : "id" 
}
EOF

HTTP/1.1 Created
x-content-type-options: nosniff
content-type: application/json

Show response body

Collection does not exist

shell> curl --header 'accept: application/json' --dump - http://localhost:8529/_api/document/doesnotexist

HTTP/1.1 Not Found
x-content-type-options: nosniff
content-type: application/json

Show response body

Simple query by-example

returns all documents of a collection matching a given example

PUT /_api/simple/by-example

This route should no longer be used. All endpoints for Simple Queries are deprecated from version 3.4.0 on. They are superseded by AQL queries.
Till ArangoDB versions 3.2.13 and 3.3.7 this API is quite expensive. A more lightweight alternative is to use the [HTTP Cursor API](aql-query-cursor.html). Starting from versions 3.2.14 and 3.3.8 this performance impact is not an issue anymore, as the internal implementation of the API has changed.

A JSON object with these properties is required:

  • collection: The name of the collection to query.

  • example: The example document.

  • skip: The number of documents to skip in the query (optional).

  • limit: The maximal amount of documents to return. The skip is applied before the limit restriction. (optional)

  • batchSize: maximum number of result documents to be transferred from the server to the client in one roundtrip. If this attribute is not set, a server-controlled default value will be used. A batchSize value of 0 is disallowed.

This will find all documents matching a given example.

Returns a cursor containing the result, see HTTP Cursor for details.

Return codes

  • 201: is returned if the query was executed successfully.

  • 400: is returned if the body does not contain a valid JSON representation of a query. The response body contains an error document in this case.

  • 404: is returned if the collection specified by collection is unknown. The response body contains an error document in this case.

Examples

Matching an attribute

shell> curl -X PUT --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/simple/by-example <<EOF
{ 
  "collection" : "products", 
  "example" : { 
    "i" : 1 
  } 
}
EOF

HTTP/1.1 Created
x-content-type-options: nosniff
content-type: application/json

Show response body

Matching an attribute which is a sub-document

shell> curl -X PUT --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/simple/by-example <<EOF
{ 
  "collection" : "products", 
  "example" : { 
    "a.j" : 1 
  } 
}
EOF

HTTP/1.1 Created
x-content-type-options: nosniff
content-type: application/json

Show response body

Matching an attribute within a sub-document

shell> curl -X PUT --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/simple/by-example <<EOF
{ 
  "collection" : "products", 
  "example" : { 
    "a" : { 
      "j" : 1 
    } 
  } 
}
EOF

HTTP/1.1 Created
x-content-type-options: nosniff
content-type: application/json

Show response body

Find documents matching an example

returns one document of a collection matching a given example

PUT /_api/simple/first-example

This route should no longer be used. All endpoints for Simple Queries are deprecated from version 3.4.0 on. They are superseded by AQL queries.
Till ArangoDB versions 3.2.13 and 3.3.7 this API is quite expensive. A more lightweight alternative is to use the [HTTP Cursor API](aql-query-cursor.html). Starting from versions 3.2.14 and 3.3.8 this performance impact is not an issue anymore, as the internal implementation of the API has changed.

A JSON object with these properties is required:

  • collection: The name of the collection to query.

  • example: The example document.

This will return the first document matching a given example.

Returns a result containing the document or HTTP 404 if no document matched the example.

If more than one document in the collection matches the specified example, only one of these documents will be returned, and it is undefined which of the matching documents is returned.

Return codes

  • 200: is returned when the query was successfully executed.

  • 400: is returned if the body does not contain a valid JSON representation of a query. The response body contains an error document in this case.

  • 404: is returned if the collection specified by collection is unknown. The response body contains an error document in this case.

Examples

If a matching document was found

shell> curl -X PUT --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/simple/first-example <<EOF
{ 
  "collection" : "products", 
  "example" : { 
    "i" : 1 
  } 
}
EOF

HTTP/1.1 OK
x-content-type-options: nosniff
content-type: application/json

Show response body

If no document was found

shell> curl -X PUT --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/simple/first-example <<EOF
{ 
  "collection" : "products", 
  "example" : { 
    "l" : 1 
  } 
}
EOF

HTTP/1.1 Not Found
x-content-type-options: nosniff
content-type: application/json

Show response body

Find documents by their keys

fetches multiple documents by their keys

PUT /_api/simple/lookup-by-keys

This route should no longer be used. All endpoints for Simple Queries are deprecated from version 3.4.0 on. They are superseded by AQL queries.

A JSON object with these properties is required:

  • collection: The name of the collection to look in for the documents

  • keys: array with the _keys of documents to remove.

Looks up the documents in the specified collection using the array of keys provided. All documents for which a matching key was specified in the keys array and that exist in the collection will be returned. Keys for which no document can be found in the underlying collection are ignored, and no exception will be thrown for them.

Equivalent AQL query:

FOR doc IN @@collection FILTER doc._key IN @keys RETURN doc

The body of the response contains a JSON object with a documents attribute. The documents attribute is an array containing the matching documents. The order in which matching documents are present in the result array is unspecified.

Return codes

  • 200: is returned if the operation was carried out successfully.

  • 404: is returned if the collection was not found. The response body contains an error document in this case.

  • 405: is returned if the operation was called with a different HTTP METHOD than PUT.

Examples

Looking up existing documents

shell> curl -X PUT --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/simple/lookup-by-keys <<EOF
{ 
  "keys" : [ 
    "test0", 
    "test1", 
    "test2", 
    "test3", 
    "test4", 
    "test5", 
    "test6", 
    "test7", 
    "test8", 
    "test9" 
  ], 
  "collection" : "test" 
}
EOF

HTTP/1.1 OK
x-content-type-options: nosniff
content-type: application/json

Show response body

Looking up non-existing documents

shell> curl -X PUT --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/simple/lookup-by-keys <<EOF
{ 
  "keys" : [ 
    "foo", 
    "bar", 
    "baz" 
  ], 
  "collection" : "test" 
}
EOF

HTTP/1.1 OK
x-content-type-options: nosniff
content-type: application/json

Show response body

Return a random document

returns a random document from a collection

PUT /_api/simple/any

This route should no longer be used. All endpoints for Simple Queries are deprecated from version 3.4.0 on. They are superseded by AQL queries.

A JSON object with these properties is required:

  • collection: The identifier or name of the collection to query.
    Returns a JSON object with the document stored in the attribute document if the collection contains at least one document. If the collection is empty, the document attribute contains null.

Returns a random document from a collection. The call expects a JSON object as body with the following attributes:

Return codes

  • 200: is returned if the query was executed successfully.

  • 400: is returned if the body does not contain a valid JSON representation of a query. The response body contains an error document in this case.

  • 404: is returned if the collection specified by collection is unknown. The response body contains an error document in this case.

Examples

shell> curl -X PUT --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/simple/any <<EOF
{ 
  "collection" : "products" 
}
EOF

HTTP/1.1 OK
x-content-type-options: nosniff
content-type: application/json

Show response body

Remove documents by their keys

removes multiple documents by their keys

PUT /_api/simple/remove-by-keys

This route should no longer be used. All endpoints for Simple Queries are deprecated from version 3.4.0 on. They are superseded by AQL queries.

A JSON object with these properties is required:

  • collection: The name of the collection to look in for the documents to remove

  • keys: array with the _keys of documents to remove.

  • options: a json object which can contains following attributes:

    • waitForSync: if set to true, then all removal operations will instantly be synchronized to disk. If this is not specified, then the collection’s default sync behavior will be applied.

    • silent: if set to false, then the result will contain an additional attribute old which contains an array with one entry for each removed document. By default, these entries will have the _id, _key and _rev attributes.

    • returnOld: if set to true and silent above is false, then the above information about the removed documents contains the complete removed documents.

Looks up the documents in the specified collection using the array of keys provided, and removes all documents from the collection whose keys are contained in the keys array. Keys for which no document can be found in the underlying collection are ignored, and no exception will be thrown for them.

Equivalent AQL query (the RETURN clause is optional):

FOR key IN @keys REMOVE key IN @@collection
  RETURN OLD

The body of the response contains a JSON object with information how many documents were removed (and how many were not). The removed attribute will contain the number of actually removed documents. The ignored attribute will contain the number of keys in the request for which no matching document could be found.

Return codes

  • 200: is returned if the operation was carried out successfully. The number of removed documents may still be 0 in this case if none of the specified document keys were found in the collection.

  • 404: is returned if the collection was not found. The response body contains an error document in this case.

  • 405: is returned if the operation was called with a different HTTP METHOD than PUT.

Examples

shell> curl -X PUT --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/simple/remove-by-keys <<EOF
{ 
  "keys" : [ 
    "test0", 
    "test1", 
    "test2", 
    "test3", 
    "test4", 
    "test5", 
    "test6", 
    "test7", 
    "test8", 
    "test9" 
  ], 
  "collection" : "test" 
}
EOF

HTTP/1.1 OK
x-content-type-options: nosniff
content-type: application/json

Show response body
shell> curl -X PUT --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/simple/remove-by-keys <<EOF
{ 
  "keys" : [ 
    "foo", 
    "bar", 
    "baz" 
  ], 
  "collection" : "test" 
}
EOF

HTTP/1.1 OK
x-content-type-options: nosniff
content-type: application/json

Show response body

Remove documents by example

removes all documents of a collection that match an example

PUT /_api/simple/remove-by-example

This route should no longer be used. All endpoints for Simple Queries are deprecated from version 3.4.0 on. They are superseded by AQL queries.

A JSON object with these properties is required:

  • collection: The name of the collection to remove from.

  • example: An example document that all collection documents are compared against.

  • options: a json object which can contains following attributes:

    • waitForSync: if set to true, then all removal operations will instantly be synchronized to disk. If this is not specified, then the collection’s default sync behavior will be applied.

    • limit: an optional value that determines how many documents to delete at most. If limit is specified but is less than the number of documents in the collection, it is undefined which of the documents will be deleted.

This will find all documents in the collection that match the specified example object.

Note: the limit attribute is not supported on sharded collections. Using it will result in an error.

Returns the number of documents that were deleted.

Return codes

  • 200: is returned if the query was executed successfully.

  • 400: is returned if the body does not contain a valid JSON representation of a query. The response body contains an error document in this case.

  • 404: is returned if the collection specified by collection is unknown. The response body contains an error document in this case.

Examples

shell> curl -X PUT --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/simple/remove-by-example <<EOF
{ 
  "collection" : "products", 
  "example" : { 
    "a" : { 
      "j" : 1 
    } 
  } 
}
EOF

HTTP/1.1 OK
x-content-type-options: nosniff
content-type: application/json

Show response body

Using Parameter: waitForSync and limit

shell> curl -X PUT --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/simple/remove-by-example <<EOF
{ 
  "collection" : "products", 
  "example" : { 
    "a" : { 
      "j" : 1 
    } 
  }, 
  "waitForSync" : true, 
  "limit" : 2 
}
EOF

HTTP/1.1 OK
x-content-type-options: nosniff
content-type: application/json

Show response body

Using Parameter: waitForSync and limit with new signature

shell> curl -X PUT --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/simple/remove-by-example <<EOF
{ 
  "collection" : "products", 
  "example" : { 
    "a" : { 
      "j" : 1 
    } 
  }, 
  "options" : { 
    "waitForSync" : true, 
    "limit" : 2 
  } 
}
EOF

HTTP/1.1 OK
x-content-type-options: nosniff
content-type: application/json

Show response body

Replace documents by example

replaces the body of all documents of a collection that match an example

PUT /_api/simple/replace-by-example

This route should no longer be used. All endpoints for Simple Queries are deprecated from version 3.4.0 on. They are superseded by AQL queries.

A JSON object with these properties is required:

  • collection: The name of the collection to replace within.

  • example: An example document that all collection documents are compared against.

  • newValue: The replacement document that will get inserted in place of the “old” documents.

  • options: a json object which can contain following attributes

    • waitForSync: if set to true, then all removal operations will instantly be synchronized to disk. If this is not specified, then the collection’s default sync behavior will be applied.

    • limit: an optional value that determines how many documents to replace at most. If limit is specified but is less than the number of documents in the collection, it is undefined which of the documents will be replaced.

This will find all documents in the collection that match the specified example object, and replace the entire document body with the new value specified. Note that document meta-attributes such as _id, _key, _from, _to etc. cannot be replaced.

Note: the limit attribute is not supported on sharded collections. Using it will result in an error.

Returns the number of documents that were replaced.

Return codes

  • 200: is returned if the query was executed successfully.

  • 400: is returned if the body does not contain a valid JSON representation of a query. The response body contains an error document in this case.

  • 404: is returned if the collection specified by collection is unknown. The response body contains an error document in this case.

Examples

shell> curl -X PUT --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/simple/replace-by-example <<EOF
{ 
  "collection" : "products", 
  "example" : { 
    "a" : { 
      "j" : 1 
    } 
  }, 
  "newValue" : { 
    "foo" : "bar" 
  }, 
  "limit" : 3 
}
EOF

HTTP/1.1 OK
x-content-type-options: nosniff
content-type: application/json

Show response body

Using new Signature for attributes WaitForSync and limit

shell> curl -X PUT --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/simple/replace-by-example <<EOF
{ 
  "collection" : "products", 
  "example" : { 
    "a" : { 
      "j" : 1 
    } 
  }, 
  "newValue" : { 
    "foo" : "bar" 
  }, 
  "options" : { 
    "limit" : 3, 
    "waitForSync" : true 
  } 
}
EOF

HTTP/1.1 OK
x-content-type-options: nosniff
content-type: application/json

Show response body

Update documents by example

partially updates the body of all documents of a collection that match an example

PUT /_api/simple/update-by-example

This route should no longer be used. All endpoints for Simple Queries are deprecated from version 3.4.0 on. They are superseded by AQL queries.

A JSON object with these properties is required:

  • collection: The name of the collection to update within.

  • example: An example document that all collection documents are compared against.

  • newValue: A document containing all the attributes to update in the found documents.

  • options: a json object which can contains following attributes:

    • keepNull: This parameter can be used to modify the behavior when handling null values. Normally, null values are stored in the database. By setting the keepNull parameter to false, this behavior can be changed so that all attributes in data with null values will be removed from the updated document.

    • waitForSync: if set to true, then all removal operations will instantly be synchronized to disk. If this is not specified, then the collection’s default sync behavior will be applied.

    • limit: an optional value that determines how many documents to update at most. If limit is specified but is less than the number of documents in the collection, it is undefined which of the documents will be updated.

    • mergeObjects: Controls whether objects (not arrays) will be merged if present in both the existing and the patch document. If set to false, the value in the patch document will overwrite the existing document’s value. If set to true, objects will be merged. The default is true.

This will find all documents in the collection that match the specified example object, and partially update the document body with the new value specified. Note that document meta-attributes such as _id, _key, _from, _to etc. cannot be replaced.

Note: the limit attribute is not supported on sharded collections. Using it will result in an error.

Returns the number of documents that were updated.

Return codes

  • 200: is returned if the collection was updated successfully and waitForSync was true.

  • 400: is returned if the body does not contain a valid JSON representation of a query. The response body contains an error document in this case.

  • 404: is returned if the collection specified by collection is unknown. The response body contains an error document in this case.

Examples

using old syntax for options

shell> curl -X PUT --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/simple/update-by-example <<EOF
{ 
  "collection" : "products", 
  "example" : { 
    "a" : { 
      "j" : 1 
    } 
  }, 
  "newValue" : { 
    "a" : { 
      "j" : 22 
    } 
  }, 
  "limit" : 3 
}
EOF

HTTP/1.1 OK
x-content-type-options: nosniff
content-type: application/json

Show response body

using new signature for options

shell> curl -X PUT --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/simple/update-by-example <<EOF
{ 
  "collection" : "products", 
  "example" : { 
    "a" : { 
      "j" : 1 
    } 
  }, 
  "newValue" : { 
    "a" : { 
      "j" : 22 
    } 
  }, 
  "options" : { 
    "limit" : 3, 
    "waitForSync" : true 
  } 
}
EOF

HTTP/1.1 OK
x-content-type-options: nosniff
content-type: application/json

Show response body

Simple range query

returns all documents of a collection within a range

PUT /_api/simple/range

This route should no longer be used. All endpoints for Simple Queries are deprecated from version 3.4.0 on. They are superseded by AQL queries.

A JSON object with these properties is required:

  • collection: The name of the collection to query.

  • attribute: The attribute path to check.

  • left: The lower bound.

  • right: The upper bound.

  • closed: If true, use interval including left and right, otherwise exclude right, but include left.

  • skip: The number of documents to skip in the query (optional).

  • limit: The maximal amount of documents to return. The skip is applied before the limit restriction. (optional)

This will find all documents within a given range. In order to execute a range query, a skip-list index on the queried attribute must be present.

Returns a cursor containing the result, see HTTP Cursor for details.

Note: the range simple query is deprecated as of ArangoDB 2.6. The function may be removed in future versions of ArangoDB. The preferred way for retrieving documents from a collection within a specific range is to use an AQL query as follows:

FOR doc IN @@collection
  FILTER doc.value >= @left && doc.value < @right
  LIMIT @skip, @limit
  RETURN doc`

Return codes

  • 201: is returned if the query was executed successfully.

  • 400: is returned if the body does not contain a valid JSON representation of a query. The response body contains an error document in this case.

  • 404: is returned if the collection specified by collection is unknown or no suitable index for the range query is present. The response body contains an error document in this case.

Examples

shell> curl -X PUT --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/simple/range <<EOF
{ 
  "collection" : "products", 
  "attribute" : "i", 
  "left" : 2, 
  "right" : 4 
}
EOF

HTTP/1.1 Created
x-content-type-options: nosniff
content-type: application/json

Show response body

Returns documents near a coordinate

returns all documents of a collection near a given location

PUT /_api/simple/near

This route should no longer be used. All endpoints for Simple Queries are deprecated from version 3.4.0 on. They are superseded by AQL queries.

A JSON object with these properties is required:

  • collection: The name of the collection to query.

  • latitude: The latitude of the coordinate.

  • longitude: The longitude of the coordinate.

  • distance: If given, the attribute key used to return the distance to the given coordinate. (optional). If specified, distances are returned in meters.

  • skip: The number of documents to skip in the query. (optional)

  • limit: The maximal amount of documents to return. The skip is applied before the limit restriction. The default is 100. (optional)

  • geo: If given, the identifier of the geo-index to use. (optional)

The default will find at most 100 documents near the given coordinate. The returned array is sorted according to the distance, with the nearest document being first in the return array. If there are near documents of equal distance, documents are chosen randomly from this set until the limit is reached.

In order to use the near operator, a geo index must be defined for the collection. This index also defines which attribute holds the coordinates for the document. If you have more than one geo-spatial index, you can use the geo field to select a particular index.

Returns a cursor containing the result, see HTTP Cursor for details.

Note: the near simple query is deprecated as of ArangoDB 2.6. This API may be removed in future versions of ArangoDB. The preferred way for retrieving documents from a collection using the near operator is to issue an AQL query using the NEAR function as follows:

FOR doc IN NEAR(@@collection, @latitude, @longitude, @limit)
  RETURN doc`

Return codes

  • 201: is returned if the query was executed successfully.

  • 400: is returned if the body does not contain a valid JSON representation of a query. The response body contains an error document in this case.

  • 404: is returned if the collection specified by collection is unknown. The response body contains an error document in this case.

Examples

Without distance

shell> curl -X PUT --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/simple/near <<EOF
{ 
  "collection" : "products", 
  "latitude" : 0, 
  "longitude" : 0, 
  "skip" : 1, 
  "limit" : 2 
}
EOF

HTTP/1.1 Created
x-content-type-options: nosniff
content-type: application/json

Show response body

With distance

shell> curl -X PUT --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/simple/near <<EOF
{ 
  "collection" : "products", 
  "latitude" : 0, 
  "longitude" : 0, 
  "skip" : 1, 
  "limit" : 3, 
  "distance" : "distance" 
}
EOF

HTTP/1.1 Created
x-content-type-options: nosniff
content-type: application/json

Show response body

Find documents within a radius around a coordinate

returns all documents of a collection within a given radius

PUT /_api/simple/within

This route should no longer be used. All endpoints for Simple Queries are deprecated from version 3.4.0 on. They are superseded by AQL queries.

A JSON object with these properties is required:

  • collection: The name of the collection to query.

  • latitude: The latitude of the coordinate.

  • longitude: The longitude of the coordinate.

  • radius: The maximal radius (in meters).

  • distance: If given, the attribute key used to return the distance to the given coordinate. (optional). If specified, distances are returned in meters.

  • skip: The number of documents to skip in the query. (optional)

  • limit: The maximal amount of documents to return. The skip is applied before the limit restriction. The default is 100. (optional)

  • geo: If given, the identifier of the geo-index to use. (optional)

This will find all documents within a given radius around the coordinate (latitude, longitude). The returned list is sorted by distance.

In order to use the within operator, a geo index must be defined for the collection. This index also defines which attribute holds the coordinates for the document. If you have more than one geo-spatial index, you can use the geo field to select a particular index.

Returns a cursor containing the result, see HTTP Cursor for details.

Note: the within simple query is deprecated as of ArangoDB 2.6. This API may be removed in future versions of ArangoDB. The preferred way for retrieving documents from a collection using the near operator is to issue an AQL query using the WITHIN function as follows:

FOR doc IN WITHIN(@@collection, @latitude, @longitude, @radius, @distanceAttributeName)
  RETURN doc

Return codes

  • 201: is returned if the query was executed successfully.

  • 400: is returned if the body does not contain a valid JSON representation of a query. The response body contains an error document in this case.

  • 404: is returned if the collection specified by collection is unknown. The response body contains an error document in this case.

Examples

Without distance

shell> curl -X PUT --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/simple/near <<EOF
{ 
  "collection" : "products", 
  "latitude" : 0, 
  "longitude" : 0, 
  "skip" : 1, 
  "limit" : 2, 
  "radius" : 500 
}
EOF

HTTP/1.1 Created
x-content-type-options: nosniff
content-type: application/json

Show response body

With distance

shell> curl -X PUT --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/simple/near <<EOF
{ 
  "collection" : "products", 
  "latitude" : 0, 
  "longitude" : 0, 
  "skip" : 1, 
  "limit" : 3, 
  "distance" : "distance", 
  "radius" : 300 
}
EOF

HTTP/1.1 Created
x-content-type-options: nosniff
content-type: application/json

Show response body

Within rectangle query

returns all documents of a collection within a rectangle

PUT /_api/simple/within-rectangle

This route should no longer be used. All endpoints for Simple Queries are deprecated from version 3.4.0 on. They are superseded by AQL queries.

A JSON object with these properties is required:

  • collection: The name of the collection to query.

  • latitude1: The latitude of the first rectangle coordinate.

  • longitude1: The longitude of the first rectangle coordinate.

  • latitude2: The latitude of the second rectangle coordinate.

  • longitude2: The longitude of the second rectangle coordinate.

  • skip: The number of documents to skip in the query. (optional)

  • limit: The maximal amount of documents to return. The skip is applied before the limit restriction. The default is 100. (optional)

  • geo: If given, the identifier of the geo-index to use. (optional)

This will find all documents within the specified rectangle (determined by the given coordinates (latitude1, longitude1, latitude2, longitude2).

In order to use the within-rectangle query, a geo index must be defined for the collection. This index also defines which attribute holds the coordinates for the document. If you have more than one geo-spatial index, you can use the geo field to select a particular index.

Returns a cursor containing the result, see HTTP Cursor for details.

Return codes

  • 201: is returned if the query was executed successfully.

  • 400: is returned if the body does not contain a valid JSON representation of a query. The response body contains an error document in this case.

  • 404: is returned if the collection specified by collection is unknown. The response body contains an error document in this case.

Examples

shell> curl -X PUT --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/simple/within-rectangle <<EOF
{ 
  "collection" : "products", 
  "latitude1" : 0, 
  "longitude1" : 0, 
  "latitude2" : 0.2, 
  "longitude2" : 0.2, 
  "skip" : 1, 
  "limit" : 2 
}
EOF

HTTP/1.1 Created
x-content-type-options: nosniff
content-type: application/json

Show response body

Fulltext index query

returns documents of a collection as a result of a fulltext query

PUT /_api/simple/fulltext

This route should no longer be used. All endpoints for Simple Queries are deprecated from version 3.4.0 on. They are superseded by AQL queries.

A JSON object with these properties is required:

  • collection: The name of the collection to query.

  • attribute: The attribute that contains the texts.

  • query: The fulltext query. Please refer to Fulltext queries for details.

  • skip: The number of documents to skip in the query (optional).

  • limit: The maximal amount of documents to return. The skip is applied before the limit restriction. (optional)

  • index: The identifier of the fulltext-index to use.

This will find all documents from the collection that match the fulltext query specified in query.

In order to use the fulltext operator, a fulltext index must be defined for the collection and the specified attribute.

Returns a cursor containing the result, see HTTP Cursor for details.

Note: the fulltext simple query is deprecated as of ArangoDB 2.6. This API may be removed in future versions of ArangoDB. The preferred way for retrieving documents from a collection using the near operator is to issue an AQL query using the FULLTEXT AQL function as follows:

FOR doc IN FULLTEXT(@@collection, @attributeName, @queryString, @limit)
  RETURN doc

Return codes

  • 201: is returned if the query was executed successfully.

  • 400: is returned if the body does not contain a valid JSON representation of a query. The response body contains an error document in this case.

  • 404: is returned if the collection specified by collection is unknown. The response body contains an error document in this case.

Examples

shell> curl -X PUT --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/simple/fulltext <<EOF
{ 
  "collection" : "products", 
  "attribute" : "text", 
  "query" : "word" 
}
EOF

HTTP/1.1 Created
x-content-type-options: nosniff
content-type: application/json

Show response body