API version: 0.3.0

---

# Placement

Every property is stored in one of the primary databases, [Neo4j](/reference/databases/neo4j.md) or
[MongoDB](/reference/databases/mongodb.md), and copied to [Elasticsearch](/reference/databases/elasticsearch.md) for the
search. Elasticsearch never holds the only copy of a value: it is not updated in real time and can be rebuilt from the
primary databases at any time, see [databases](/reference/databases.md).

## Data roles

Schemas name the databases by the role they play for the data, not by their product, so that a database can be replaced
without changing every schema. Today the roles are served by these databases:

| Name in schemas | Role                                                                        | Database today |
| --------------- | --------------------------------------------------------------------------- | -------------- |
| `graph`         | Primary database for properties which the graph and the Cypher search use   | Neo4j          |
| `document`      | Primary database for large and structured values                            | MongoDB        |
| `search`        | Copy for the search, never the only one, switched with the setting `search` | Elasticsearch  |

`storage` and `placement.roles` accept `graph` and `document`. The product names `neo4j`, `mongodb` and `elasticsearch`
are rejected with `400 Bad Request` there. Everything which is specific to a database keeps its name: the per database
overrides of `index`, the raw settings `neo4j` and `elasticsearch`, and the `indices` of a schema.

## Placement roles

Where a property is stored is decided by its placement role, which follows from its [type](/reference/schemas/types.md):

| Placement role | Types                                                                             | Default database                                        | Possible databases                             |
| -------------- | --------------------------------------------------------------------------------- | ------------------------------------------------------- | ---------------------------------------------- |
| `scalar`       | `boolean`, `integer`, `number`, `string`, `datetime`, `elementId`                 | Neo4j, MongoDB for strings of more than 1024 characters | Neo4j, MongoDB                                 |
| `structured`   | `object`, `list`                                                                  | MongoDB                                                 | MongoDB                                        |
| `vector`       | `vector`                                                                          | MongoDB                                                 | Neo4j, MongoDB                                 |
| `geo`          | `point`, `linestring`, `polygon`, `multipoint`, `multilinestring`, `multipolygon` | MongoDB                                                 | MongoDB; Neo4j only for `point` with `storage` |

## Settings

Settings only apply to properties which a schema of a non-built-in type defines, and are resolved in this order:
`storage` of the property, `placement.roles` of the type, `placement.roles` of the schema `default`, the built-in
placement.

```json
{
  "placement": {
    "roles": {
      "vector": "graph",
      "scalar": "graph"
    },
    "search": true
  },
  "properties": {
    "spot": {
      "type": "point",
      "storage": "graph"
    },
    "notes": {
      "type": "string",
      "search": false
    },
    "archive": {
      "type": "object"
    }
  }
}
```

- `storage` is `graph` or `document`. The graph database has no objects, lists and geometries other than points, so
  these types can
  only be stored in the document database; asking for `graph` is rejected with `400 Bad Request`. The placement role
  `geo` can not be moved to
  the graph database as a whole, only single `point` properties with `"storage": "graph"`.
- `search` (on the property, or in `placement` for the whole type) decides whether the property is part of the search
  copy in Elasticsearch. It only controls the copy, the value is stored in a primary database either way.
- The schema named `default` is created automatically and holds the `placement` for all types, `default` is not
  usable as a type of elements.
- `storage: graph` on a `string` limits it to 1024 characters: a longer value is rejected with `400 Bad Request` when it
  is written, and a `maxLength` above 1024 is rejected when the schema is saved. Without `storage`, longer strings go to
  the document database instead.

## Changing the placement

The data of existing elements is not moved between databases yet. Changes of `placement`, `storage` or `search` of an
existing schema are therefore only accepted while no existing value has to move:

- Changes which don't change where values are stored are always accepted, e.g. a `storage` which names the database
  where the property is stored anyway.
- `storage` and `search` of a property can be changed while no element of the type has a value for the property, e.g.
  for a property which is added with the same change.
- The `placement` of a type can be changed while the type has no elements.
- The `placement` of the schema `default` applies to every type and can't be changed once it exists.

Everything else answers with `409 Conflict`, which names the properties whose values would have to move. While the check
and the save run, writes of elements of the type answer with [`423 Locked`](/api/get-error-423-locked.md). Schemas which
are created, and backups, can define the placement freely.

Properties which no schema defines follow their value: scalars and strings of up to 1024 characters are stored in
Neo4j, everything else in MongoDB.

## Default placement from the first element

The `placement` of the schema `default` applies as soon as a type exists, also to the first element of a type which has
no schema of its own yet: the `search` setting of `default` decides if the properties of such elements are part of the
search copy, and its `placement.roles` apply as well. Properties without a definition get their placement role from
the value: objects and lists are `structured`, everything else is `scalar` (geometries and vectors are only recognized
with a definition). A role is only applied where the database can store it, e.g. `structured` values never go to the
graph.

## Moving values between databases

A property is stored in exactly one primary database. If the value of a property moves, e.g. a string which grows past
1024 characters and now belongs to MongoDB, or one which shrinks again, the old copy is removed from the database
the value left, so reading the element always returns the current value. Properties which are meant to be in more than
one database, like `name`, are not affected.

## Configured placement fails loudly

If `storage` of a property, or a placement role, asks for Neo4j and a value can not be stored there, the request fails
with `500 Internal Server Error` and a message which names the property, instead of silently storing the value somewhere
else. The silent fallback to MongoDB (e.g. strings of more than 1024 characters) only applies if no schema configured
the placement of the property.

---

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

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

Previous: [Vector](/reference/schemas/types/vector.md)

Next: [Rules](/reference/schemas/rules.md)
