start #
Compares a collection with a full target model and returns the plan: every change, and whether it applies in place or needs a copy of the collection. Nothing changes unless apply is true.
With apply: true, changes that are all in place (new fields, root dynamic / _meta) are applied at once, and the existing documents reindexed by an Elasticsearch background task; any other change starts a copy job, which closes the collection's writes until it ends. See How a migration works.
Query Syntax #
HTTP #
URL: http://kuzzle:7512/_/mapping-migration/migration/start?index=<index>&collection=<collection>[&apply=true][&allowFailures=true]
Method: POST
Body:{
"mappings": {
"dynamic": "false", // optional
"_meta": {}, // optional
"properties": {
// every field of the target model
}
},
"renames": { // optional
"<old.dotted.path>": "<new.dotted.path>"
},
"settings": {}, // optional
"fingerprint": "<fingerprint of the reviewed dry run>" // optional
}Other protocols #
{
"controller": "mapping-migration/migration",
"action": "start",
"index": "<index>",
"collection": "<collection>",
"apply": false,
"allowFailures": false,
"body": {
"mappings": { "properties": { /* ... */ } },
"renames": {},
"settings": {},
"fingerprint": "<fingerprint>"
}
}Kourou #
kourou mapping-migration/migration:start -a index=<index> -a collection=<collection> --body '{
"mappings": { "properties": { "code": { "type": "long" } } }
}'Arguments #
| Argument | Type | Description |
|---|---|---|
index | string | Index of the collection |
collection | string | Collection to migrate |
apply | boolean | Apply the plan. Default false: a dry run, that only returns the plan. Over HTTP: true, the bare flag (?apply) or false; any other value is refused (invalid_flag) |
allowFailures | boolean | Switch to the new model even if some documents fail to copy; they are then only kept in the archive, until purge. Default false: the job aborts on failed documents. Same HTTP values as apply |
Body properties #
| Property | Type | Description |
|---|---|---|
mappings | object | Required. The full target model: a field left out is a field removed. Root keys: properties (required, every field), dynamic, _meta (compared only when given) |
renames | object | Fields renamed, old dotted path → new dotted path, so that their values are kept. The old path must be a field of the collection and not in the target; the new path a field of the target and not of the collection |
settings | object | Index settings to change, in any shape Elasticsearch takes ({ "index": { "refresh_interval": "5s" } }, { "refresh_interval": "5s" }, { "index.refresh_interval": "5s" }, analysis…). Any setting needs a copy |
fingerprint | string | The fingerprint of the dry run you reviewed: start refuses (plan_changed, 412) if the plan computed now differs. Checked whenever given, dry run included |
Response #
{
"changes": [
{
"kind": "fieldTypeChanged",
"path": "code",
"inPlace": false,
"current": { "type": "keyword" },
"target": { "type": "long" }
},
{
"kind": "fieldRenamed",
"path": "location",
"renamedTo": "place",
"inPlace": false,
"current": { "properties": { "city": { "type": "keyword" } } },
"target": { "properties": { "city": { "type": "keyword" } } }
}
],
"copyRequired": true,
"fingerprint": "5d0c…",
"dryRun": false,
"applied": false,
"job": {
"jobId": "…",
"index": "iot",
"collection": "sensors",
"phase": "waiting",
// ... see status
}
}| Property | Type | Description |
|---|---|---|
changes | object[] | Every change, see change kinds. Empty when the collection already has the target model: nothing is applied, even with apply |
copyRequired | boolean | true when at least one change needs a copy of the collection |
fingerprint | string | SHA-256 (hex) of the collection's current mapping, the request (mappings, renames, settings) and the changes |
dryRun | boolean | true when nothing was applied (no apply) |
applied | boolean | true only when the new model is already live: changes applied in place. false for a dry run, for a copy just started, and when there is no change |
job | object | Only when a copy starts: the job, as status returns it. Its jobId is the one status, failures and purge take |
reindex | object | Only when changes are applied in place: the background reindex of the existing documents, { taskId, index, collection, startedAt }, followed with status (index, collection). null if Kuzzle did not report its task: the reindex runs, but cannot be followed |
Change kinds #
Each change has a kind, a path (dotted field path, root parameter name, or settings), inPlace (false when it needs a copy), and current / target, the definition before and after when they exist.
kind | path | inPlace | Meaning |
|---|---|---|---|
fieldAdded | New field | true | A field of the target not in the collection. target is its definition |
fieldRemoved | Removed field | false | A mapped field of the collection left out of the target. Its values are dropped from the copied documents. current is its definition |
fieldTypeChanged | Field | false | The field's type differs (a plain object's implicit type is object) |
fieldModified | Field | false | Same type, but another parameter of its definition differs (index, analyzer, ignore_above, fields, format…) |
fieldRenamed | Old path | false | A rename declared in renames; renamedTo is the new path. The values move to the new path. Sub-fields of a renamed object that change are listed as their own changes under the new path |
rootParameterChanged | dynamic or _meta | true | A root parameter the target sets differs from the collection's |
settingsChanged | settings | false | settings is not empty (even if the values equal the current ones). target is the settings requested, nested and without the index level |
Sub-fields of an object are compared one by one: a change inside place.city is listed with the path place.city, not as a change of place.
Possible errors #
| Error id | Status | When |
|---|---|---|
plugin.mapping-migration.invalid_mappings | 400 | mappings has no properties object, or another root key than properties, dynamic, _meta |
plugin.mapping-migration.invalid_renames | 400 | A rename's paths do not fit the collection and the target |
plugin.mapping-migration.invalid_target | 400 | Elasticsearch refuses the target model or settings (nothing locked) |
plugin.mapping-migration.invalid_flag | 400 | Over HTTP, apply or allowFailures is neither true, false nor the bare flag |
plugin.mapping-migration.forbidden | 403 | Missing collection:getMapping (dry run) or collection:update (apply) on the collection |
plugin.mapping-migration.job_running | 412 | A migration is already running |
plugin.mapping-migration.not_enough_disk_space | 412 | No room for a copy below the high disk watermark |
plugin.mapping-migration.plan_changed | 412 | fingerprint does not match the plan computed now |
plugin.mapping-migration.unsupported_engine | 412 | Kuzzle does not run on Elasticsearch 8 |
services.storage.unknown_index, services.storage.unknown_collection | 412 | The collection does not exist |
services.storage.collection_locked | 503 | The collection is locked by someone else, or new fields applied in place while it is being copied |
See Errors for what to do.