ArangoDB v3.8 reached End of Life (EOL) and is no longer supported.

This documentation is outdated. Please see the most recent version at docs.arangodb.com

Working with TTL (time-to-live) Indexes

Create TTL index

creates a TTL (time-to-live) index

POST /_api/index

Query Parameters

  • collection (string, required): The collection name.

Request Body

  • type (string, required): must be equal to “ttl”.

  • fields (array of strings, required): an array with exactly one attribute path.

  • expireAfter (number, required): The time interval (in seconds) from the point in time stored in the fields attribute after which the documents count as expired. Can be set to 0 to let documents expire as soon as the server time passes the point in time stored in the document attribute, or to a higher number to delay the expiration.

  • inBackground (boolean, optional): The optional attribute inBackground can be set 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 is false.

Creates a TTL index for the collection collection-name if it does not already exist. The call expects an object containing the index details.

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 400: If the collection already contains another TTL index, then an HTTP 400 is returned, as there can be at most one TTL index per collection.

HTTP 404: If the collection-name is unknown, then a HTTP 404 is returned.

Examples

Creating a TTL index

shell> curl -X POST --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/index?collection=sessions <<EOF
{ 
  "type" : "ttl", 
  "expireAfter" : 3600, 
  "fields" : [ 
    "createdAt" 
  ] 
}
EOF

HTTP/1.1 201 Created
content-type: application/json
connection: Keep-Alive
content-length: 205
server: ArangoDB
x-content-type-options: nosniff
Show response body