API version: 0.3.0

---

# Defining a schema

Every node label and relation type has a [schema](/reference/schemas.md). 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:

| Property               | Type                                             | Meaning                                          |
| ---------------------- | ------------------------------------------------ | ------------------------------------------------ |
| `name`                 | [`string`](/reference/schemas/types/string.md)   | The name of the place, required.                 |
| `location`             | [`point`](/reference/schemas/types/point.md)     | The center of the place, required.               |
| `area`                 | [`polygon`](/reference/schemas/types/polygon.md) | The area of the place, here a bounding box.      |
| `population`           | [`integer`](/reference/schemas/types/integer.md) | The number of inhabitants.                       |
| `elevation`            | [`number`](/reference/schemas/types/number.md)   | The height above sea level in meters.            |
| `coastal`              | [`boolean`](/reference/schemas/types/boolean.md) | Whether the place lies at the coast.             |
| `climate`              | [`object`](/reference/schemas/types/object.md)   | Temperatures in °C and precipitation in mm/year. |
| `descriptionEmbedding` | [`vector`](/reference/schemas/types/vector.md)   | An 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](/reference/roles-and-capabilities.md). Tokens only carry the capabilities which they ask for, so
create a token for such a user with [`POST /token`](/api/post-token.md) and request `schema.manage` in `capabilities`:

```bash
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
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:

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

See [authentication](/guide/authentication.md) for more about tokens.

## Step 2: Defining the schema of places

A schema is written with [`PUT /schema/<type>`](/api/put-schema.md), here `PUT /schema/Place`:

```bash
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
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](/reference/schemas.md#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](/reference/indices.md).
- `location` and `area` are [geo values](/reference/formats-and-languages/geojson.md). The intent `geo` gives them a
  `2dsphere` index in
  MongoDB, see [geo indices](/reference/indices/geo.md).
- `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](/reference/indices/vector.md) 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](/reference/schemas.md#visibility).

Like the writes of elements, the response has no body. [`GET /schema/<type>`](/api/get-schema.md) returns the schema
node, with every setting spelled out:

```bash
curl \
  -H 'Authorization: Bearer secret-token:LkFR5OTYejnPWgmYepCYSO' \
  https://api.example.com/schema/Place
```

```http
HTTP/1.1 200 OK
```

```json
{
  "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](/reference/schemas/placement.md): 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](/reference/schemas/migrations.md).
[`GET /schema/<type>/plan`](/api/get-schema-plan.md) shows what a migration would do, without changing anything:

```bash
curl \
  -H 'Authorization: Bearer secret-token:LkFR5OTYejnPWgmYepCYSO' \
  https://api.example.com/schema/Place/plan
```

```http
HTTP/1.1 200 OK
```

```json
{
  "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`](/api/post-migration.md) stores the plan as a migration:

```bash
curl \
  -H 'Authorization: Bearer secret-token:LkFR5OTYejnPWgmYepCYSO' \
  -H 'Content-Type: application/json' \
  -d '{
        "schemaName": "Place"
      }' \
  https://api.example.com/migration
```

```http
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>`](/api/patch-migration.md) runs it:

```bash
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
HTTP/1.1 204 No Content
```

The background job [`migration:listen`](/command/migration-listen.md) of every instance runs a queued migration right
away. Poll [`GET /migration/<uuid>`](/api/get-migration.md) until its `status` is `succeeded`; it
shows the result of every step:

```bash
curl \
  -H 'Authorization: Bearer secret-token:LkFR5OTYejnPWgmYepCYSO' \
  'https://api.example.com/migration/<uuid of the migration>'
```

```http
HTTP/1.1 200 OK
```

```json
{
  "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](/reference/schemas/built-in-schemas.md).

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 /`](/api/post-index.md):

```bash
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
HTTP/1.1 201 Created
Location: /02IiNr0GPLgGXr5nUZDH97KgabD5yE4EyzOla
```

`location` is sent as [WKT](/reference/formats-and-languages/geojson.md#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:

```bash
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
HTTP/1.1 400 Bad Request
```

## Step 6: Reading the place back

[`GET /<uuid>`](/api/get-element.md) returns the place, whichever database stores which property. The hidden vector is
not part of the response:

```bash
curl \
  -H 'Authorization: Bearer secret-token:LkFR5OTYejnPWgmYepCYSO' \
  'https://api.example.com/<uuid of the place>'
```

```http
HTTP/1.1 200 OK
```

```json
{
  "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](/reference/formats-and-languages/geojson.md#response-format):

```bash
curl \
  -H 'Authorization: Bearer secret-token:LkFR5OTYejnPWgmYepCYSO' \
  -H 'Prefer: geometry=wkt' \
  'https://api.example.com/<uuid of the place>'
```

```http
HTTP/1.1 200 OK
Preference-Applied: geometry=wkt
```

```json
{
  "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>`](/api/patch-schema.md), and plan and run a migration afterwards.
- Switch to `strict` once the shape is stable.
- Add [rules](/guide/writing-schema-rules.md) 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](/reference/schemas.md).

Every change of a schema creates a revision, see [`GET /schema/<type>/revisions`](/api/get-schema-revisions.md), and
[`DELETE /schema/<type>`](/api/delete-schema.md) resets it to the default.

---

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

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

Previous: [Caching and conditional requests](/guide/caching-and-conditional-requests.md)

Next: [Writing schema rules](/guide/writing-schema-rules.md)
