API version: 0.3.0

---

# Elasticsearch

[Elasticsearch](https://www.elastic.co/elasticsearch) is a secondary database. It holds a copy of the properties of
every element for the [search](/reference/search.md), one index per type (`node_<lowercase label>` or
`relation_<lowercase type>`). It never holds the only copy of a value, see
[why Elasticsearch is secondary](/reference/databases.md#why-elasticsearch-is-secondary).

Elasticsearch 8.12 or newer is required, e.g. for kNN queries inside of search queries. Versions up to 9.5 are tested.

## What it stores

Every property is copied and indexed, unless the property or its type sets `"search": false`, see
[placement](/reference/schemas/placement.md). This differs from Neo4j and MongoDB, which only index what a schema asks for:
Elasticsearch is the search engine of the API, so it is optimized for common search queries without any definition. The
mapping of a property follows its [type](/reference/schemas/types.md), e.g.
`geo_point` for points and `dense_vector` for vectors, and can be replaced with a
[raw Elasticsearch mapping](/reference/indices/raw-indices/elasticsearch.md). Files are not copied.

Written documents become searchable after the next refresh, about one second after the write.

## Limits

- **1000 fields per index**: Elasticsearch counts every mapped field of an index, including nested properties and the
  `keyword` sub-fields of strings, and rejects mappings with more than `index.mapping.total_fields.limit` fields, 1000
  by default. A schema with many properties, or with deeply nested objects, can therefore make its migration step fail.
  Raise the setting of the index in Elasticsearch before the migration is run, or exclude properties from the search
  with `"search": false`.
- **20 levels of nesting**: objects can be mapped at most `index.mapping.depth.limit` levels deep, 20 by default.
- **4096 dimensions per vector**: `dense_vector` fields have at most 4096 dimensions, see
  [vector](/reference/schemas/types/vector.md).
- **Long keywords**: the `keyword` sub-field of strings, and the `keyword` field of a string with only `exact`, ignore
  values of more than 256 characters (`ignore_above`). Such values can not be found by their exact value, only by the
  words of the `text` field, if the string has one. A raw Elasticsearch mapping can set another limit.

## Migrations

Creating the index and adding fields or dynamic templates is not left to migrations alone: it is also done when a schema
is saved and after a [backup load](/command/backup-load.md), so that the index never starts with a dynamic mapping (the
steps `create-elasticsearch-index` and `update-elasticsearch-mapping`). If the plan contains a blocking step, e.g.
because of an incompatible field, nothing is applied to Elasticsearch, and errors are logged and do not fail the save. A
[migration](/reference/schemas/migrations.md) creates the index of the type (`node_<lowercase label>` or
`relation_<lowercase type>`) with the mapping of the schema if it does not exist, and adds fields which the schema
defines but the index does not have. Fields are never removed. Existing fields which do not match the schema (e.g. a
`string` property, whose existing field is a number) can not be changed in place: the plan contains a step which fails
with a description, fix the data or the schema, or reindex manually. This also applies to a changed `index` or
`similarity` of a vector, to changed parameters of a raw `elasticsearch` mapping (only the parameters which the schema
sets are compared), and to a missing `keyword` sub field of a field which asks for both `exact` and `fulltext`.
Properties without raw settings accept the mappings which Elasticsearch created on its own for the same values. Objects
with `"additionalProperties": false` are mapped `dynamic: strict`, and the typed `additionalProperties` of objects
become dynamic templates (named `ember_<path>`), so that further properties are mapped as defined. Dynamic templates
which were not created by schemas are never touched. Failing steps, for incompatible fields and for indices which the
version can not provide (e.g. `bit` vectors need Elasticsearch 8.15), are blocking and run before any step of any
database, so nothing has changed when they fail.

## See also

- [Mapping limit settings](https://www.elastic.co/docs/reference/elasticsearch/index-settings/mapping-limit)
- [Elasticsearch's type documentation](https://www.elastic.co/docs/reference/elasticsearch/mapping-reference/field-data-types)

---

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

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

Previous: [MongoDB](/reference/databases/mongodb.md)

Next: [S3](/reference/databases/s3.md)
