Appwrite icon

Appwrite

Interact with Appwrite API

Actions181

Index → Create

AI-generated

Overview

This node operation creates an index in a specified database collection within the Appwrite platform. It is useful for organizing and optimizing data retrieval by defining keys, types, and sorting orders for attributes in the collection. Practical examples include creating unique indexes for user IDs, fulltext indexes for search functionality, or key indexes for sorting data.

Use Case Examples

  1. Creating a unique index on a user email attribute to ensure no duplicates.
  2. Creating a fulltext index on a product description attribute to enable search capabilities.
  3. Creating a key index on multiple attributes to optimize query performance.

Properties

Name Meaning
Database ID The ID of the database where the index will be created.
Collection ID The ID of the collection within the database where the index will be created.
Index Key The key name for the index.
Type The type of the index, which can be key, fulltext, or unique.
Attributes A comma-separated string of attribute keys that the index will cover.
Orders A comma-separated string of sort orders (ASC or DESC) for the attributes. If empty, default order is used.

Output

JSON

  • indexId - The unique identifier of the created index.
  • databaseId - The ID of the database where the index was created.
  • collectionId - The ID of the collection where the index was created.
  • key - The key name of the created index.
  • type - The type of the created index (key, fulltext, unique).
  • attributes - The list of attribute keys included in the index.
  • orders - The sort orders applied to the attributes in the index.

Dependencies

  • Appwrite API key credential for authentication and access to the Appwrite service.

Troubleshooting

  • Ensure that the provided database ID and collection ID exist and are accessible with the given credentials.
  • Verify that the index key is unique within the collection to avoid conflicts when creating a unique index.
  • Check that the attributes string is correctly formatted as a comma-separated list without extra spaces or invalid characters.
  • If the orders string is provided, ensure it only contains valid values (ASC or DESC) separated by commas.
  • Common error messages may include authentication failures, invalid resource IDs, or malformed input parameters. Verify credentials and input data to resolve these issues.

Discussion