createIndex( )


Creates an index for a data collection.

The index can't be used immediately, as the process of generating the index takes time. You can check whether an index is ready by calling List Indexes.

Note that when an index fails to create, the failed index still occupies a slot. To remove the failed index and free up the slot for a new index, call Drop Index.

Authentication

This function requires elevated permissions and runs only on the backend and on dashboard pages.

Permissions
Manage Data Indexes
Manage All Data Resources
Learn more about app permissions.
Method Declaration
Copy
function createIndex(
  dataCollectionId: string,
  index: Index,
  options: CreateIndexOptions,
): Promise<Index>;
Method Parameters
dataCollectionIdstringRequired

ID of the data collection for which to generate the index.


indexIndexRequired

Details of the index to be created.


optionsCreateIndexOptions

Options for creating an index.

Returns
Return Type:Promise<Index>
JavaScript
import { indexes } from "wix-data.v2"; /* * Sample dataCollectionId value = 'Jackets' * * Sample index value: * { * fields: [ * { * path: 'price' * } * ], * name: 'byPrice' * } */ export async function myCreateIndexFunction(dataCollectionId, index) { try { const createIndexResponse = await indexes.createIndex( dataCollectionId, index, ); console.log( `Successfully created an index named ${createIndexResponse.name}. Full response: `, createIndexResponse, ); return createIndexResponse; } catch (error) { console.error(error); // Handle the error } } /* Promise resolves to: * { * "caseInsensitive": false, * "fields": [ * { * "order": "ASC", * "path": "price" * } * ], * "name": "byPrice", * "status": "BUILDING", * "unique": false, * } */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?