HTTP interface for TTL (time-to-live) indexes

Create a TTL index

POST /_db/{database-name}/_api/index
Creates a time-to-live (TTL) index for the collection collection-name if it does not already exist.
Path Parameters
  • The name of the database.

Query Parameters
  • The collection name.

HTTP Headers
    Request Body application/json object
    • 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.

    • A list with exactly one attribute path.

    • Set this option to true to keep the collection/shards available for write operations by not using an exclusive write lock for the duration of the index creation.

    • 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.

    • Must be equal to "ttl".

    Responses
    • The index exists already.

    • The index is created as there is no such existing index.

    • There is already a TTL index for the collection but there can only be one.

    • The collection is unknown.

    Examples

    Creating a TTL index

    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
    Show output