---
title: "Create index"
method: POST
path: "/_fabric/{fabric}/_api/index/general"
tags: ["Indexes"]
---

# Create index

`POST /_fabric/{fabric}/_api/index/general`

## Request

- The document declares no server URL.
- Auth: one of:
  - API key in header `Authorization`
  - HTTP bearer
- TypeScript: <https://skmtc.dev/macrometa/apis/macrometa-api-reference/docs/_fabric/:fabric/_api/index/general/post.ts> (a function with typed inputs; its response is checked against the schema)

Create a new index.

**Note**: Indexing the system attribute _id is not supported for user-defined indexes. Manually creating an index using _id as an index attribute fails with an error.

## Path parameters

- `fabric` string, string, required

## Query parameters

- `collection` string, required

## Request body

- ApiIndexGeneralBody
  - `fields` string[], required: An array of attribute names. Currently, the array is limited to exactly one attribute.
  - `name` string: Name of index.
  - `type` string, required: Must be equal to *"fulltext"*.
  - `sparse` boolean: *True* if index is sparse type. **Note**: Hash, skiplist and persistent indexes can optionally be created in a sparse variant. Sparse indexes do not index documents for which any of the index attributes is either not set or is null.
  - `unique` boolean: *True* if index is unique. **Note**: Unique indexes on non-shard keys are not supported in a cluster. The following index types do not support uniqueness and using the *unique* attribute with these types may lead to an error: - geo indexes - fulltext indexes
  - `deduplicate` boolean: *True* it controls whether inserting duplicate index values from the same document into a unique array index leads to a unique constraint error or not.

## Response `200`

Successfully fetched existing index.

- ApiIndexPostFulltextHttpExamplesRc200
  - `code` integer: HTTP response code.
  - `error` boolean: Flag if there is an error in response. *False* for this response.
  - `fields` string[]: Array of fields on which index is created.
  - `id` string: Index identifier.
  - `name` string: Name of the index.
  - `selectivityEstimate` number: The selectivity estimate of index.
  - `sparse` boolean: *True* if index is sparse type.
  - `type` string: Index type.
  - `unique` boolean: *True* if index is unique.
  - `expireAfter` number: Index expiry time.

## Other responses

- `201`: Successfully created index.
- `400`: Failed due to missing or malformed data. Verify that all parameters are complete.
- `403`: Failed because you do not have access to the server.
- `404`: Failed to find specified collection.

---

[API](https://skmtc.dev/macrometa/apis/macrometa-api-reference.md) - [All operations](https://skmtc.dev/macrometa/apis/macrometa-api-reference/llms.txt) - [OpenAPI document](https://skmtc.dev/macrometa/apis/macrometa-api-reference/revisions/2006b6d7f31d?raw)
