> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> 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`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - 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 | validation: maxLength 256
   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 | validation: minLength 1, maxLength 128
        - name: fields | type: array<Field> | description: Fields for which the index is defined.  Max: 3 fields (for a unique index: 1 field) | required: true | validation: minItems 1, maxItems 3
           - name: path | type: string | description: Path of the field to index. For example: `title` or `options.price`.  | validation: minLength 1, maxLength 128
           - 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.  | read-only: true | validation: format GUID
     - name: name | type: string | description: Name of the index.  | validation: minLength 1, maxLength 128
     - name: fields | type: array<Field> | description: Fields for which the index is defined.  Max: 3 fields (for a unique index: 1 field)  | validation: minItems 1, maxItems 3
        - name: path | type: string | description: Path of the field to index. For example: `title` or `options.price`.  | validation: minLength 1, maxLength 128
        - 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.  | read-only: true 
         - 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`.  | read-only: true 
        - 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.  | validation: maxLength 7
        - name: description | type: string | description: Description of the failure.  | validation: maxLength 1024
        - 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.  | validation: maxLength 16000
     - 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: <AUTH>' \
-d '{
  "dataCollectionId": "my-collection",
  "index": {
    "name": "my-index",
    "fields": [
      {
         "path": "my-field",
         "order": "ASC"
      }
    ],
    "unique": false,
    "caseInsensitive": false
   }
}'
```

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.data.indexes.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 | validation: maxLength 256
   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 | validation: minLength 1, maxLength 128
        - name: fields | type: array<Field> | description: Fields for which the index is defined.  Max: 3 fields (for a unique index: 1 field) | required: true | validation: minItems 1, maxItems 3
           - name: path | type: string | description: Path of the field to index. For example: `title` or `options.price`.  | validation: minLength 1, maxLength 128
           - 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<Index>
  - name: _id | type: string | description: GUID of the index.  | read-only: true | validation: format GUID
  - name: name | type: string | description: Name of the index.  | validation: minLength 1, maxLength 128
  - name: fields | type: array<Field> | description: Fields for which the index is defined.  Max: 3 fields (for a unique index: 1 field)  | validation: minItems 1, maxItems 3
     - name: path | type: string | description: Path of the field to index. For example: `title` or `options.price`.  | validation: minLength 1, maxLength 128
     - 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.  | read-only: true 
     - 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`.  | read-only: true 
     - 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.  | validation: maxLength 7
     - name: description | type: string | description: Description of the failure.  | validation: maxLength 1024
     - 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.  | validation: maxLength 16000
  - 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-managed)
Self-managed 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);
};
```

---