SDK
SDK Javascript v7.x
2

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

Options #

Additional query options

Options Type
(default)
Description
queuable
boolean

(true)
If true, queues the request during downtime, until connected to Kuzzle again
refresh
string

("")
If set to wait_for, waits for the change to be reflected for search (up to 1s)
timeout
number
Time (in ms) during which a request will still be waited to be resolved. Set it -1 if you want to wait indefinitely
Available since 7.4.0

definition #

An object containing:

Copied to clipboard!
const definition = {
  mappings: {
    properties: {
      field1: { type: 'text' },
      field2: {
        properties: {
          nestedField: { type: 'keyword' }
        }
      }
    }    
  },
  settings: {
    // index settings (e.g. analyzers)
  }
};
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 mappings = {
  dynamic: 'false',
  _meta: {
    area: 'Panipokhari'
  },
  properties: {
    plate: { type: 'keyword' }
  }
};
try {
  await kuzzle.collection.update('nyc-open-data', 'yellow-taxi', { mappings });
  console.log('Success');
} catch (error) {
  console.error(error.message);
}