# Create JSON index

Source: https://stratadb.org/docs/reference/json/index/create

Creates a secondary index over one JSON field path with a numeric, tag, or text kind. Existing documents are indexed at creation and future writes maintain the index automatically. The current wire response is a transitional bare index definition.

Successful mutations return an acknowledgement that identifies the affected target, the mutation effect, and commit facts when the operation changed stored state.

## Examples

Create a secondary index on a JSON field.

### CLI

```console
$ strata json index create by_name $.name tag
$ strata json index list
```

### Wire

```json
{"field_path":"$.name","index_type":"tag","name":"by_name","type":"json_create_index"}
{"type":"json_list_indexes"}
```

## Parameters

| Name | Type | Required | Description |
|---|---|---|---|
| `field_path` | `string` | yes | Indexed field path. |
| `index_type` | `JsonIndexType` | yes | Index kind. |
| `name` | `string` | yes | Index name. |

Plus the optional scope: `branch` and `space` (default to the session branch and the `"default"` space).

## Returns

`MutationAck<JsonIndexCreate>`.

## Errors

- [`failed_precondition.engine.runtime_closed`](https://stratadb.org/e/failed_precondition.engine.runtime_closed)
- [`not_found.engine.branch`](https://stratadb.org/e/not_found.engine.branch)
- [`invalid_argument.engine.product_space`](https://stratadb.org/e/invalid_argument.engine.product_space)
- [`invalid_argument.engine.json_index_name`](https://stratadb.org/e/invalid_argument.engine.json_index_name)
- [`invalid_argument.engine.json_index_name_reserved`](https://stratadb.org/e/invalid_argument.engine.json_index_name_reserved)
- [`invalid_argument.engine.json_path`](https://stratadb.org/e/invalid_argument.engine.json_path)
- [`invalid_argument.engine.json_path_too_long`](https://stratadb.org/e/invalid_argument.engine.json_path_too_long)
- [`already_exists.engine.json_index`](https://stratadb.org/e/already_exists.engine.json_index)

## Invocation

- CLI: `strata json index create`
- Wire type: `json_create_index`