Placement
Every property is stored in one of the primary databases, or , and copied to 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 .
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 :
| 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.
{ "placement": { "roles": { "vector": "graph", "scalar": "graph" }, "search": true }, "properties": { "spot": { "type": "point", "storage": "graph" }, "notes": { "type": "string", "search": false }, "archive": { "type": "object" } }}storageisgraphordocument. The graph database has no objects, lists and geometries other than points, so these types can only be stored in the document database; asking forgraphis rejected with400 Bad Request. The placement rolegeocan not be moved to the graph database as a whole, only singlepointproperties with"storage": "graph".search(on the property, or inplacementfor 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
defaultis created automatically and holds theplacementfor all types,defaultis not usable as a type of elements.storage: graphon astringlimits it to 1024 characters: a longer value is rejected with400 Bad Requestwhen it is written, and amaxLengthabove 1024 is rejected when the schema is saved. Withoutstorage, 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
storagewhich names the database where the property is stored anyway. storageandsearchof 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
placementof a type can be changed while the type has no elements. - The
placementof the schemadefaultapplies 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 . 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.