Skip to main content

Defining a schema

Every node label and relation type has a schema. Until you define one, the schema accepts every property, which is the right choice while you explore your data. Once you know its shape, a schema checks every write, tells the databases which properties to index, and decides where each property is stored.

This guide defines a schema for places, e.g. cities, step by step.

A place has these properties:

PropertyTypeMeaning
namestringThe name of the place, required.
locationpointThe center of the place, required.
areapolygonThe area of the place, here a bounding box.
populationintegerThe number of inhabitants.
elevationnumberThe height above sea level in meters.
coastalbooleanWhether the place lies at the coast.
climateobjectTemperatures in °C and precipitation in mm/year.
descriptionEmbeddingvectorAn embedding of a description of the place.

Step 1: Getting a token

Changing schemas needs the capability schema.manage, which users with the role admin have, see roles and capabilities. Tokens only carry the capabilities which they ask for, so create a token for such a user with POST /token and request schema.manage in capabilities:

curl \
-H 'Content-Type: application/json' \
-d '{
"type": "Token",
"uniqueUserIdentifier": "admin@roles.user.endpoint.localhost.dev",
"password": "1234",
"capabilities": [
"schema.manage"
]
}' \
https://api.example.com/token
HTTP/1.1 201 Created

The response contains the token. Send it in the Authorization header of all further requests, as Authorization: Bearer secret-token:...; the commands below use the token of this response:

{
"type": "_TokenResponse",
"token": "secret-token:LkFR5OTYejnPWgmYepCYSO"
}

See authentication for more about tokens.

Step 2: Defining the schema of places

A schema is written with PUT /schema/<type>, here PUT /schema/Place:

curl -X PUT \
-H 'Authorization: Bearer secret-token:LkFR5OTYejnPWgmYepCYSO' \
-H 'Content-Type: application/json' \
-d '{
"mode": "partial",
"properties": {
"name": {
"type": "string",
"required": true,
"maxLength": 100,
"index": [
"exact",
"fulltext"
]
},
"location": {
"type": "point",
"required": true,
"index": "geo"
},
"area": {
"type": "polygon",
"index": "geo"
},
"population": {
"type": "integer",
"index": "exact"
},
"elevation": {
"type": "number"
},
"coastal": {
"type": "boolean"
},
"climate": {
"type": "object",
"properties": {
"temperatureMin": {
"type": "number"
},
"temperatureMax": {
"type": "number"
},
"temperatureAvg": {
"type": "number"
},
"precipitation": {
"type": "number"
}
},
"additionalProperties": false
},
"descriptionEmbedding": {
"type": "vector",
"dimensions": 4,
"index": "vector"
}
}
}' \
https://api.example.com/schema/Place
HTTP/1.1 201 Created
Location: /schema/Place

Going through the definition from top to bottom:

  • mode partial checks the properties which the schema defines and accepts further ones. strict would reject them, auto checks nothing, see modes.
  • name is required and at most 100 characters long. It is indexed twice: exact for lookups and sorting, fulltext for the words in it, see indices.
  • location and area are geo values. The intent geo gives them a 2dsphere index in MongoDB, see geo indices.
  • population gets an exact index for range queries, e.g. all places with more than 100000 inhabitants. elevation and coastal are only stored.
  • climate is an object whose properties are defined as well. "additionalProperties": false rejects other keys, so a misspelled key is rejected instead of silently stored.
  • descriptionEmbedding is a vector of exactly four numbers. Real embeddings have hundreds of dimensions, four keep the example short. Vectors are hidden by default: the schema response states "visibility": "hidden", the value is stored and searchable, but element responses leave it out, see visibility.

Like the writes of elements, the response has no body. GET /schema/<type> returns the schema node, with every setting spelled out:

curl \
-H 'Authorization: Bearer secret-token:LkFR5OTYejnPWgmYepCYSO' \
https://api.example.com/schema/Place
HTTP/1.1 200 OK
{
"type": "Schema",
"id": "02IiNr0GPQNf48VjK3WYp1zZTsyRhiWfmGJJd",
"data": {
"name": "Place",
"kind": "node",
"builtIn": false,
"version": 1,
"mode": "partial",
"properties": {
"name": {
"type": "string",
"required": true,
"maxLength": 100,
"index": [
"exact",
"fulltext"
]
},
"location": {
"type": "point",
"required": true,
"dimensions": 2,
"index": [
"geo"
]
},
"area": {
"type": "polygon",
"required": false,
"dimensions": 2,
"index": [
"geo"
]
},
"population": {
"type": "integer",
"required": false,
"index": [
"exact"
]
},
"elevation": {
"type": "number",
"required": false
},
"coastal": {
"type": "boolean",
"required": false
},
"climate": {
"type": "object",
"required": false,
"properties": {
"temperatureMin": {
"type": "number",
"required": false
},
"temperatureMax": {
"type": "number",
"required": false
},
"temperatureAvg": {
"type": "number",
"required": false
},
"precipitation": {
"type": "number",
"required": false
}
},
"additionalProperties": false
},
"descriptionEmbedding": {
"type": "vector",
"required": false,
"dimensions": 4,
"elementType": "float",
"similarity": "cosine",
"visibility": "hidden",
"index": [
"vector"
]
}
},
"files": null,
"rules": [],
"placement": null,
"indices": null,
"createdAt": "2026-12-04T01:36:20+00:00",
"createdBy": "02IiNr0GPDtGWj0ND8tzBin5iLwibNVGtjWWU",
"updatedAt": "2026-12-04T01:36:20+00:00",
"updatedBy": "02IiNr0GPDtGWj0ND8tzBin5iLwibNVGtjWWU"
}
}

The data of this response can be edited and sent back with PUT: the fields which the API sets (name, kind, builtIn, version, createdAt, …) are accepted as long as they match the stored schema.

The schema is active right away: from now on, every write of a Place is validated. Where each property is stored follows from its type, see placement: the scalar values (name, population, elevation, coastal) live in the graph database (Neo4j), the geo values, the object and the vector in the document database (MongoDB), and all of them are copied to Elasticsearch for the search.

Step 3: Planning the migration

The schema only describes the indices, nothing has been created in the databases yet. This is on purpose: creating indices can take a long time for big types, so it is a separate step, a migration. GET /schema/<type>/plan shows what a migration would do, without changing anything:

curl \
-H 'Authorization: Bearer secret-token:LkFR5OTYejnPWgmYepCYSO' \
https://api.example.com/schema/Place/plan
HTTP/1.1 200 OK
{
"type": "_MigrationPlan",
"schemaName": "Place",
"kind": "node",
"schemaVersion": 1,
"steps": [
{
"target": "neo4j",
"action": "create-index",
"name": "ens_place_name_exact_1e320186",
"description": "Create a range index on property 'name'.",
"statement": "CREATE RANGE INDEX `ens_place_name_exact_1e320186` IF NOT EXISTS FOR (e:`Place`) ON (e.`name`)",
"blocking": false
},
{
"target": "neo4j",
"action": "create-index",
"name": "ens_place_name_fulltext_8d922fd4",
"description": "Create a fulltext index on property 'name'.",
"statement": "CREATE FULLTEXT INDEX `ens_place_name_fulltext_8d922fd4` IF NOT EXISTS FOR (e:`Place`) ON EACH [e.`name`]",
"blocking": false
},
{
"target": "neo4j",
"action": "create-index",
"name": "ens_place_population_exact_3d8e4f7b",
"description": "Create a range index on property 'population'.",
"statement": "CREATE RANGE INDEX `ens_place_population_exact_3d8e4f7b` IF NOT EXISTS FOR (e:`Place`) ON (e.`population`)",
"blocking": false
},
{
"target": "mongodb",
"action": "create-index",
"name": "ens_place_location_geo_f9354867",
"description": "Create a 2dsphere index on property 'location' of the MongoDB collection 'Place'.",
"statement": {
"operation": "create-index",
"collection": "Place",
"name": "ens_place_location_geo_f9354867",
"key": {
"location": "2dsphere"
}
},
"blocking": false
},
{
"target": "mongodb",
"action": "create-index",
"name": "ens_place_area_geo_1e5a8e26",
"description": "Create a 2dsphere index on property 'area' of the MongoDB collection 'Place'.",
"statement": {
"operation": "create-index",
"collection": "Place",
"name": "ens_place_area_geo_1e5a8e26",
"key": {
"area": "2dsphere"
}
},
"blocking": false
}
]
}

Every step names its database (target), what it does and why, and shows the statement which it would execute. Read the plan before you run it, especially when a schema changes: steps which drop indices are listed as well.

Step 4: Running the migration

POST /migration stores the plan as a migration:

curl \
-H 'Authorization: Bearer secret-token:LkFR5OTYejnPWgmYepCYSO' \
-H 'Content-Type: application/json' \
-d '{
"schemaName": "Place"
}' \
https://api.example.com/migration
HTTP/1.1 201 Created
Location: /migration/02IiNr0GPLiTIqtt3gc78PTWp8FhbBKFXLyD4

The Location header contains the id of the migration, <uuid of the migration> in the following commands. Setting its status to queued with PATCH /migration/<uuid> runs it:

curl -X PATCH \
-H 'Authorization: Bearer secret-token:LkFR5OTYejnPWgmYepCYSO' \
-H 'Content-Type: application/json' \
-d '{
"status": "queued"
}' \
'https://api.example.com/migration/<uuid of the migration>'
HTTP/1.1 204 No Content

The background job migration:listen of every instance runs a queued migration right away. Poll GET /migration/<uuid> until its status is succeeded; it shows the result of every step:

curl \
-H 'Authorization: Bearer secret-token:LkFR5OTYejnPWgmYepCYSO' \
'https://api.example.com/migration/<uuid of the migration>'
HTTP/1.1 200 OK
{
"type": "Migration",
"id": "02IiNr0GPOmvF7jAkwNGB8diUUXCCUdxyM2zE",
"data": {
"_steps": [
{
"target": "neo4j",
"action": "create-index",
"name": "ens_place_name_exact_1e320186",
"description": "Create a range index on property 'name'.",
"statement": "CREATE RANGE INDEX `ens_place_name_exact_1e320186` IF NOT EXISTS FOR (e:`Place`) ON (e.`name`)",
"blocking": false,
"status": "succeeded",
"error": null
},
{
"target": "neo4j",
"action": "create-index",
"name": "ens_place_name_fulltext_8d922fd4",
"description": "Create a fulltext index on property 'name'.",
"statement": "CREATE FULLTEXT INDEX `ens_place_name_fulltext_8d922fd4` IF NOT EXISTS FOR (e:`Place`) ON EACH [e.`name`]",
"blocking": false,
"status": "succeeded",
"error": null
},
{
"target": "neo4j",
"action": "create-index",
"name": "ens_place_population_exact_3d8e4f7b",
"description": "Create a range index on property 'population'.",
"statement": "CREATE RANGE INDEX `ens_place_population_exact_3d8e4f7b` IF NOT EXISTS FOR (e:`Place`) ON (e.`population`)",
"blocking": false,
"status": "succeeded",
"error": null
},
{
"target": "mongodb",
"action": "create-index",
"name": "ens_place_location_geo_f9354867",
"description": "Create a 2dsphere index on property 'location' of the MongoDB collection 'Place'.",
"statement": {
"operation": "create-index",
"collection": "Place",
"name": "ens_place_location_geo_f9354867",
"key": {
"location": "2dsphere"
}
},
"blocking": false,
"status": "succeeded",
"error": null
},
{
"target": "mongodb",
"action": "create-index",
"name": "ens_place_area_geo_1e5a8e26",
"description": "Create a 2dsphere index on property 'area' of the MongoDB collection 'Place'.",
"statement": {
"operation": "create-index",
"collection": "Place",
"name": "ens_place_area_geo_1e5a8e26",
"key": {
"area": "2dsphere"
}
},
"blocking": false,
"status": "succeeded",
"error": null
}
],
"schemaVersion": 1,
"kind": "node",
"startedAt": "2026-12-03T13:00:29+00:00",
"schemaName": "Place",
"finishedAt": "2026-12-03T13:00:30+00:00",
"queuedAt": "2026-12-03T13:00:29+00:00",
"stepCount": 5,
"status": "succeeded",
"createdAt": "2026-12-03T13:00:28+00:00",
"createdBy": "02IiNr0GPDtGWj0ND8tzBin5iLwibNVGtjWWU",
"updatedAt": "2026-12-03T13:00:30+00:00",
"updatedBy": "02IiNr0GOoKiPMLSxpKrArvUWmaEqZ5h7Uybr"
}
}

The internal property _steps is only part of the response because the token has the capability schema.manage, see built-in schemas.

A migration with the status succeeded has created all indices. If a step fails, the migration stops there and keeps the error; fix the cause and queue it again with PATCH /migration/<uuid> and {"status": "queued"}, which continues with the failed step.

Step 5: Writing an element

Elements of the type are created like every other element, with POST /:

curl \
-H 'Authorization: Bearer secret-token:LkFR5OTYejnPWgmYepCYSO' \
-H 'Content-Type: application/json' \
-d '{
"type": "Place",
"data": {
"name": "Kiel",
"location": "POINT (10.1228 54.3233)",
"area": {
"type": "Polygon",
"coordinates": [
[
[
10.03,
54.25
],
[
10.22,
54.25
],
[
10.22,
54.43
],
[
10.03,
54.43
],
[
10.03,
54.25
]
]
]
},
"population": 247000,
"elevation": 5,
"coastal": true,
"climate": {
"temperatureMin": -1.2,
"temperatureMax": 21.8,
"temperatureAvg": 9.1,
"precipitation": 778
},
"descriptionEmbedding": [
0.12,
-0.48,
0.33,
0.8
]
}
}' \
https://api.example.com/
HTTP/1.1 201 Created
Location: /02IiNr0GPLgGXr5nUZDH97KgabD5yE4EyzOla

location is sent as WKT and area as GeoJSON: both formats are accepted for every geo property. The response contains the id of the new place in its Location header, which is <uuid of the place> in the following commands.

A value which does not match the schema is refused with 400 Bad Request before anything is stored, e.g. a name with more than 100 characters, a point outside the valid coordinates, or a vector with three numbers instead of four. Here the population is "many" instead of a number:

curl \
-H 'Authorization: Bearer secret-token:LkFR5OTYejnPWgmYepCYSO' \
-H 'Content-Type: application/json' \
-d '{
"type": "Place",
"data": {
"name": "Atlantis",
"location": "POINT (0 0)",
"population": "many"
}
}' \
https://api.example.com/
HTTP/1.1 400 Bad Request

Step 6: Reading the place back

GET /<uuid> returns the place, whichever database stores which property. The hidden vector is not part of the response:

curl \
-H 'Authorization: Bearer secret-token:LkFR5OTYejnPWgmYepCYSO' \
'https://api.example.com/<uuid of the place>'
HTTP/1.1 200 OK
{
"type": "Place",
"id": "02IiNr0GPOftBjeR5uvPnlYO9KK5nBRp2L3Ew",
"data": {
"location": {
"type": "Point",
"coordinates": [
10.1228,
54.3233
]
},
"area": {
"type": "Polygon",
"coordinates": [
[
[
10.03,
54.25
],
[
10.22,
54.25
],
[
10.22,
54.43
],
[
10.03,
54.43
],
[
10.03,
54.25
]
]
]
},
"climate": {
"temperatureMin": -1.2,
"temperatureMax": 21.8,
"temperatureAvg": 9.1,
"precipitation": 778
},
"name": "Kiel",
"elevation": 5,
"population": 247000,
"coastal": true,
"createdAt": "2026-12-03T12:06:38+00:00",
"createdBy": "02IiNr0GPDtGWj0ND8tzBin5iLwibNVGtjWWU",
"updatedAt": "2026-12-03T12:06:38+00:00",
"updatedBy": "02IiNr0GPDtGWj0ND8tzBin5iLwibNVGtjWWU"
}
}

The location, which was written as WKT, is returned as GeoJSON, the default format. Clients which prefer WKT ask for it with the Prefer header, see response format:

curl \
-H 'Authorization: Bearer secret-token:LkFR5OTYejnPWgmYepCYSO' \
-H 'Prefer: geometry=wkt' \
'https://api.example.com/<uuid of the place>'
HTTP/1.1 200 OK
Preference-Applied: geometry=wkt
{
"type": "Place",
"id": "02IiNr0GPOftBjeR5uvPnlYO9KK5nBRp2L3Ew",
"data": {
"location": "POINT (10.1228 54.3233)",
"area": "POLYGON ((10.03 54.25, 10.22 54.25, 10.22 54.43, 10.03 54.43, 10.03 54.25))",
"climate": {
"temperatureMin": -1.2,
"temperatureMax": 21.8,
"temperatureAvg": 9.1,
"precipitation": 778
},
"name": "Kiel",
"elevation": 5,
"population": 247000,
"coastal": true,
"createdAt": "2026-12-03T12:06:38+00:00",
"createdBy": "02IiNr0GPDtGWj0ND8tzBin5iLwibNVGtjWWU",
"updatedAt": "2026-12-03T12:06:38+00:00",
"updatedBy": "02IiNr0GPDtGWj0ND8tzBin5iLwibNVGtjWWU"
}
}

Preference-Applied confirms the format, and the ETag carries the suffix -wkt, as the response differs from the GeoJSON one.

Next steps

  • Add properties with PATCH /schema/<type>, and plan and run a migration afterwards.
  • Switch to strict once the shape is stable.
  • Add rules for checks which the property types can not express, e.g. that temperatureMin is not larger than temperatureMax.
  • Look up every type and setting in the schema reference.

Every change of a schema creates a revision, see GET /schema/<type>/revisions, and DELETE /schema/<type> resets it to the default.