Javascript 7.x

update

Available since Kuzzle 2.1.0

You can define the collection dynamic mapping policy by setting the dynamic field to the desired value.

You can define collection additional metadata within the _meta root field.

Available since Kuzzle 2.2.0 Available since 7.4.0

You can also provide Elasticsearch index settings when creating a new collection.


Copied to clipboard!
update(index, collection, definition);

Arguments Type Description
index
string
Index name
collection
string
Collection name
definition
object
Describes the collection mappings and the ES index settings
options
object
Query options
Available since 7.4.0
Deprecated since 7.4.0

definition

An object representing the data mappings of the collection.

The mappings must have a root field properties that contain the mappings properties definition:

Copied to clipboard!
const mappings = {
  properties: {
    field1: { type: 'text' },
    field2: {
      properties: {
        nestedField: { type: 'keyword' }
      }
    }
  }
};

More informations about database mappings here.

Resolves

Resolve if the collection is successfully updated.

Usage

Copied to clipboard!
const mapping = {
  dynamic: 'false',
  _meta: {
    area: 'Panipokhari'
  },
  properties: {
    plate: { type: 'keyword' }
  }
};
try {
  await kuzzle.collection.update('nyc-open-data', 'yellow-taxi', mapping);
  console.log('Success');
} catch (error) {
  console.error(error.message);
}