> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt # CreateIndex # Package: collectionManagement # Namespace: IndexService # Method link: https://dev.wix.com/docs/api-reference/business-solutions/cms/collection-management/indexes/create-index.md ## Permission Scopes: Manage Data Indexes: SCOPE.DC-DATA.INDEXES-MANAGE ## Introduction 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. --- ## REST API ### Schema ``` Method: createIndex Description: 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. URL: https://www.wixapis.com/wix-data/v2/indexes Method: POST # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present. Required parameters: dataCollectionId, index, index.name, index.fields, index.fields.path Method parameters: param name: dataCollectionId | type: dataCollectionId | description: GUID of the data collection for which to generate the index. | required: true param name: index | type: Index | description: An index is a map of a collection's data, organized according to specific fields to increase query speed. | required: true - name: name | type: string | description: Name of the index. | required: true - name: fields | type: array | description: Fields for which the index is defined. Max: 3 fields (for a unique index: 1 field) | required: true - name: path | type: string | description: Path of the field to index. For example: `title` or `options.price`. - name: order | type: Order | description: Sort order for the index. Base on how the data is regularly queried. Default: `ASC` - enum: ASC, DESC - name: unique | type: boolean | description: Whether the index enforces uniqueness of values in the field for which it's defined. If `true`, the index can have only 1 field. Default: `false` - name: caseInsensitive | type: boolean | description: Whether the index ignores case. Default: `false` - name: source | type: IndexSource | description: Source of the index. See index sources in [Index Types](https://dev.wix.com/docs/api-reference/business-solutions/cms/indexes/index-types.md#index-sources). Default: `USER` - enum: - SYSTEM: Automatically created by Wix for all collections. System indexes are created for essential attributes, such as ID and creation date. You can't delete them and they don't count towards the index limit. - USER: Created by a Wix user via the API or in the dashboard. - AUTO: Created automatically by Wix based on a Wix user's queries. For large collections, Wix identifies slow-running queries and creates indexes automatically to improve performance. These indexes don't count towards the index limit. They're created dynamically, and may be deleted if they no longer fit the system's parameters. To keep an automatic index permanently, manually create an identical `USER` index. Return type: CreateIndexResponse - name: index | type: Index | description: Details of the index being generated. - name: id | type: string | description: GUID of the index. - name: name | type: string | description: Name of the index. - name: fields | type: array | description: Fields for which the index is defined. Max: 3 fields (for a unique index: 1 field) - name: path | type: string | description: Path of the field to index. For example: `title` or `options.price`. - name: order | type: Order | description: Sort order for the index. Base on how the data is regularly queried. Default: `ASC` - enum: ASC, DESC - name: status | type: Status | description: Current status of the index. - enum: - UNKNOWN: Place holder. Never returned by the service. - BUILDING: Index creation is in progress. - ACTIVE: Index has been successfully created and can be used in queries. - DROPPING: Index is in the process of being dropped. - DROPPED: Index has been dropped successfully. - FAILED: Index creation has failed. - INVALID: Index contains incorrectly indexed data. - name: failure | type: Failure | description: Contains details about the reasons for failure when `status` is `FAILED`. - name: code | type: string | description: Error code. - `WDE0112`: Unknown error while building collection index. - `WDE0113`: Duplicate key error while building collection index. - `WDE0114`: Document too large while building collection index. - name: description | type: string | description: Description of the failure. - name: itemId | type: string | description: GUID of the data item that caused the failure. For example, if `unique` is `true`, the GUID of an item containing a duplicate value. - name: unique | type: boolean | description: Whether the index enforces uniqueness of values in the field for which it's defined. If `true`, the index can have only 1 field. Default: `false` - name: caseInsensitive | type: boolean | description: Whether the index ignores case. Default: `false` - name: source | type: IndexSource | description: Source of the index. See index sources in [Index Types](https://dev.wix.com/docs/api-reference/business-solutions/cms/indexes/index-types.md#index-sources). Default: `USER` - enum: - SYSTEM: Automatically created by Wix for all collections. System indexes are created for essential attributes, such as ID and creation date. You can't delete them and they don't count towards the index limit. - USER: Created by a Wix user via the API or in the dashboard. - AUTO: Created automatically by Wix based on a Wix user's queries. For large collections, Wix identifies slow-running queries and creates indexes automatically to improve performance. These indexes don't count towards the index limit. They're created dynamically, and may be deleted if they no longer fit the system's parameters. To keep an automatic index permanently, manually create an identical `USER` index. ``` ### Examples ### Create an index for a collection ```curl curl -X POST \ 'https://www.wixapis.com/wix-data/v2/indexes' \ -H 'Content-Type: application/json' \ -H 'Authorization: ' \ -d '{ "dataCollectionId": "my-collection", "index": { "name": "my-index", "fields": [ { "path": "my-field", "order": "ASC" } ], "unique": false, "caseInsensitive": false } }' ``` --- ## JavaScript SDK ### Schema ``` Method: wixClientAdmin.collectionManagement.IndexService.createIndex(dataCollectionId, index) Description: 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. # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present. Required parameters: dataCollectionId, index, index.name, index.fields, index.fields.path Method parameters: param name: dataCollectionId | type: string | description: GUID of the data collection for which to generate the index. | required: true param name: index | type: CreateIndex | description: An index is a map of a collection's data, organized according to specific fields to increase query speed. | required: true - name: name | type: string | description: Name of the index. | required: true - name: fields | type: array | description: Fields for which the index is defined. Max: 3 fields (for a unique index: 1 field) | required: true - name: path | type: string | description: Path of the field to index. For example: `title` or `options.price`. - name: order | type: Order | description: Sort order for the index. Base on how the data is regularly queried. Default: `ASC` - enum: ASC, DESC - name: unique | type: boolean | description: Whether the index enforces uniqueness of values in the field for which it's defined. If `true`, the index can have only 1 field. Default: `false` - name: caseInsensitive | type: boolean | description: Whether the index ignores case. Default: `false` - name: source | type: IndexSource | description: Source of the index. See index sources in [Index Types](https://dev.wix.com/docs/api-reference/business-solutions/cms/indexes/index-types.md#index-sources). Default: `USER` - enum: - SYSTEM: Automatically created by Wix for all collections. System indexes are created for essential attributes, such as ID and creation date. You can't delete them and they don't count towards the index limit. - USER: Created by a Wix user via the API or in the dashboard. - AUTO: Created automatically by Wix based on a Wix user's queries. For large collections, Wix identifies slow-running queries and creates indexes automatically to improve performance. These indexes don't count towards the index limit. They're created dynamically, and may be deleted if they no longer fit the system's parameters. To keep an automatic index permanently, manually create an identical `USER` index. Return type: PROMISE - name: _id | type: string | description: GUID of the index. - name: name | type: string | description: Name of the index. - name: fields | type: array | description: Fields for which the index is defined. Max: 3 fields (for a unique index: 1 field) - name: path | type: string | description: Path of the field to index. For example: `title` or `options.price`. - name: order | type: Order | description: Sort order for the index. Base on how the data is regularly queried. Default: `ASC` - enum: ASC, DESC - name: status | type: Status | description: Current status of the index. - enum: - UNKNOWN: Place holder. Never returned by the service. - BUILDING: Index creation is in progress. - ACTIVE: Index has been successfully created and can be used in queries. - DROPPING: Index is in the process of being dropped. - DROPPED: Index has been dropped successfully. - FAILED: Index creation has failed. - INVALID: Index contains incorrectly indexed data. - name: failure | type: Failure | description: Contains details about the reasons for failure when `status` is `FAILED`. - name: code | type: string | description: Error code. - `WDE0112`: Unknown error while building collection index. - `WDE0113`: Duplicate key error while building collection index. - `WDE0114`: Document too large while building collection index. - name: description | type: string | description: Description of the failure. - name: itemId | type: string | description: GUID of the data item that caused the failure. For example, if `unique` is `true`, the GUID of an item containing a duplicate value. - name: unique | type: boolean | description: Whether the index enforces uniqueness of values in the field for which it's defined. If `true`, the index can have only 1 field. Default: `false` - name: caseInsensitive | type: boolean | description: Whether the index ignores case. Default: `false` - name: source | type: IndexSource | description: Source of the index. See index sources in [Index Types](https://dev.wix.com/docs/api-reference/business-solutions/cms/indexes/index-types.md#index-sources). Default: `USER` - enum: - SYSTEM: Automatically created by Wix for all collections. System indexes are created for essential attributes, such as ID and creation date. You can't delete them and they don't count towards the index limit. - USER: Created by a Wix user via the API or in the dashboard. - AUTO: Created automatically by Wix based on a Wix user's queries. For large collections, Wix identifies slow-running queries and creates indexes automatically to improve performance. These indexes don't count towards the index limit. They're created dynamically, and may be deleted if they no longer fit the system's parameters. To keep an automatic index permanently, manually create an identical `USER` index. ``` ### Examples ### createIndex ```javascript import { indexes } from '@wix/data'; async function createIndex(dataCollectionId,index) { const response = await indexes.createIndex(dataCollectionId,index); }; ``` ### createIndex (with elevated permissions) ```javascript import { indexes } from '@wix/data'; import { auth } from '@wix/essentials'; async function myCreateIndexMethod(dataCollectionId,index) { const elevatedCreateIndex = auth.elevate(indexes.createIndex); const response = await elevatedCreateIndex(dataCollectionId,index); } ``` ### createIndex (self-hosted) Self-hosted SDK calls require you to [create a client](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-the-wix-client.md). ```javascript import { createClient } from '@wix/sdk'; import { indexes } from '@wix/data'; // Import the auth strategy for the relevant access type // Import the relevant host module if needed const myWixClient = createClient ({ modules: { indexes }, // Include the auth strategy and host as relevant }); async function createIndex(dataCollectionId,index) { const response = await myWixClient.indexes.createIndex(dataCollectionId,index); }; ``` ---