Working with TTL (time-to-live) Indexes
Create TTL index
creates a TTL (time-to-live) index
POST /_api/index#ttl
Query Parameters
- collection (required): The collection name.
A JSON object with these properties is required:
-
type: must be equal to “ttl”.
-
fields: an array with exactly one attribute path.
-
expireAfter: The time (in seconds) after a document’s creation after which the documents count as “expired”.
Creates a TTL index for the collection collection-name if it does not already exist. The call expects an object containing the index details.
Return codes
-
200: If the index already exists, then a HTTP 200 is returned.
-
201: If the index does not already exist and could be created, then a HTTP 201 is returned.
-
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.
-
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 Created
content-type: application/json
x-content-type-options: nosniff