Database
Indexes
Optimize query performance and enforce uniqueness with indexes.
Indexes improve the speed of document retrieval. You must create an index for any attribute you want to filter or sort by.
Index management is an administrative task. Use the Nuvix Console or REST API with an API Key.
Index types
| Type | Description | Use Case |
|---|---|---|
key | Standard B-tree index | Exact match, ranges, sorting |
unique | Enforces unique values | Usernames, emails, slugs |
fulltext | Text search index | Keyword search (.search()) |
Creating indexes
Key Index (Filtering/Sorting)
Create a key index to filter or sort by an attribute.
curl -X POST https://api.nuvix.in/v1/schemas/my_app/collections/articles/indexes \
-H "X-Project-ID: <PROJECT_ID>" \
-H "X-API-Key: <YOUR_API_KEY>" \
-H "Content-Type: application/json" \
-d '{
"key": "idx_status_views",
"type": "key",
"attributes": ["status", "views"],
"orders": ["ASC", "DESC"]
}'Unique Index
Prevent duplicate values for an attribute.
curl -X POST https://api.nuvix.in/v1/schemas/my_app/collections/users/indexes \
-H "X-Project-ID: <PROJECT_ID>" \
-H "X-API-Key: <YOUR_API_KEY>" \
-H "Content-Type: application/json" \
-d '{
"key": "idx_email_unique",
"type": "unique",
"attributes": ["email"],
"orders": ["ASC"]
}'Fulltext Index
Enable search functionality on string attributes.
curl -X POST https://api.nuvix.in/v1/schemas/my_app/collections/articles/indexes \
-H "X-Project-ID: <PROJECT_ID>" \
-H "X-API-Key: <YOUR_API_KEY>" \
-H "Content-Type: application/json" \
-d '{
"key": "idx_content_search",
"type": "fulltext",
"attributes": ["title", "content"],
"orders": ["ASC", "ASC"]
}'Listing indexes
curl -X GET https://api.nuvix.in/v1/schemas/my_app/collections/articles/indexes \
-H "X-Project-ID: <PROJECT_ID>" \
-H "X-API-Key: <YOUR_API_KEY>"Deleting indexes
curl -X DELETE https://api.nuvix.in/v1/schemas/my_app/collections/articles/indexes/idx_status_views \
-H "X-Project-ID: <PROJECT_ID>" \
-H "X-API-Key: <YOUR_API_KEY>"Index rules
- Ordering: Attribute order matters. If you index
["status", "created"], you can filter bystatusalone orstatus + created, but NOTcreatedalone. - String Size: Attributes in a
keyoruniqueindex should generally be limited in size (e.g., string length < 255 chars). Large text fields should usefulltext. - Limits: While there is no hard limit on the number of indexes, too many can slow down write operations.
Status
Like attributes, index creation happens in the background. The status will change from processing to available (or failed) once the index is built.
How is this guide?
Last update: