API version: 0.3.0

---

# `index:ensure`

Creates a range index on the `id` property for every node label and every relationship type which does not have one
yet. Elements are looked up by their id on almost every request; with a label (or relationship type) in the query and
an index on it, Neo4j finds the element directly instead of scanning the whole graph.

Options:

- `--nodes-only` / `--relations-only` - only handle node labels or only relationship types.
- `--wait[=<seconds>]` - waits until the new indices are online, at most the given number of seconds (default 600).
- `--dry-run` - only lists the indices which would be created.

Index names are deterministic, `eni_<type>_<hash>`, with the same rules as the
[index names](/reference/indices.md#index-names) of schemas (`ens_`): the type lowercased, characters outside `a-z`, `0-9`
and `_` replaced with `_`, at most 32 characters, and 8 hexadecimal characters of xxh3 over the kind and the exact type.
Types which already have an equivalent index under another name (for example from a uniqueness constraint) are left
alone. The command only creates indices, with one exception: indices which earlier versions created with the prefix
`ember_nexus_` are replaced by the index with the current name. MongoDB and Elasticsearch need nothing, as the element
id is the document identifier there.

> **ℹ Info**
>
> Every API instance runs this command every ten minutes (see
> [Background tasks](/reference/configuration.md#background-tasks)), so indices of newly used types appear on their own.
> The command is skipped (successfully) while another instance is already creating indices, or while a backup is
> being loaded or the database is being reset.

## Help

```bash
php bin/console index:ensure --help
```

```text
Description:
  Creates the id indices of all node labels and relationship types which do not have one yet.

Usage:
  index:ensure [options]

Options:
      --nodes-only      Only create indices for node labels.
      --relations-only  Only create indices for relationship types.
      --wait[=WAIT]     Wait until the new indices are online, at most the given number of seconds. [default: false]
      --dry-run         Only list the indices which would be created.
  -h, --help            Display help for the given command. When no command is given display help for the list command
      --silent          Do not output any message
  -q, --quiet           Only errors are displayed. All other output is suppressed
  -V, --version         Display this application version
      --ansi|--no-ansi  Force (or disable --no-ansi) ANSI output
  -n, --no-interaction  Do not ask any interactive question
  -e, --env=ENV         The Environment name. [default: "prod"]
      --no-debug        Switch off debug mode.
      --profile         Enables profiling (requires debug).
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
```

## Example

```bash
php bin/console index:ensure
```

```text
    ▄
  ▄▀ ▀▄  Ember Nexus API
   ▀█▀   v0.3.0, production mode

  Index ensure

  Neo4j: 0 created, 0 already existed, 0 covered by an index under another name.
  MongoDB and Elasticsearch: nothing to do, the element id is the document identifier there.
▶ Done.
```

---

Home: [Ember Nexus API docs](/index.md)

Full site map: [llms.txt](/llms.txt)

Previous: [database:drop](/command/database-drop.md)

Next: [mphf:build](/command/mphf-build.md)
