This plugin is part of the Kuzzle Enterprise Plan. If you are interested, please contact us.

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 #

ArgumentTypeDescription
indexstringIndex of the collection
collectionstringCollection to migrate
applybooleanApply 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)
allowFailuresbooleanSwitch 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 #

PropertyTypeDescription
mappingsobjectRequired. The full target model: a field left out is a field removed. Root keys: properties (required, every field), dynamic, _meta (compared only when given)
renamesobjectFields 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
settingsobjectIndex 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
fingerprintstringThe 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
  }
}
PropertyTypeDescription
changesobject[]Every change, see change kinds. Empty when the collection already has the target model: nothing is applied, even with apply
copyRequiredbooleantrue when at least one change needs a copy of the collection
fingerprintstringSHA-256 (hex) of the collection's current mapping, the request (mappings, renames, settings) and the changes
dryRunbooleantrue when nothing was applied (no apply)
appliedbooleantrue 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
jobobjectOnly when a copy starts: the job, as status returns it. Its jobId is the one status, failures and purge take
reindexobjectOnly 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.

kindpathinPlaceMeaning
fieldAddedNew fieldtrueA field of the target not in the collection. target is its definition
fieldRemovedRemoved fieldfalseA mapped field of the collection left out of the target. Its values are dropped from the copied documents. current is its definition
fieldTypeChangedFieldfalseThe field's type differs (a plain object's implicit type is object)
fieldModifiedFieldfalseSame type, but another parameter of its definition differs (index, analyzer, ignore_above, fields, format…)
fieldRenamedOld pathfalseA 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
rootParameterChangeddynamic or _metatrueA root parameter the target sets differs from the collection's
settingsChangedsettingsfalsesettings 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 idStatusWhen
plugin.mapping-migration.invalid_mappings400mappings has no properties object, or another root key than properties, dynamic, _meta
plugin.mapping-migration.invalid_renames400A rename's paths do not fit the collection and the target
plugin.mapping-migration.invalid_target400Elasticsearch refuses the target model or settings (nothing locked)
plugin.mapping-migration.invalid_flag400Over HTTP, apply or allowFailures is neither true, false nor the bare flag
plugin.mapping-migration.forbidden403Missing collection:getMapping (dry run) or collection:update (apply) on the collection
plugin.mapping-migration.job_running412A migration is already running
plugin.mapping-migration.not_enough_disk_space412No room for a copy below the high disk watermark
plugin.mapping-migration.plan_changed412fingerprint does not match the plan computed now
plugin.mapping-migration.unsupported_engine412Kuzzle does not run on Elasticsearch 8
services.storage.unknown_index, services.storage.unknown_collection412The collection does not exist
services.storage.collection_locked503The collection is locked by someone else, or new fields applied in place while it is being copied

See Errors for what to do.