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.


update(index, collection, definition);

ArgumentsTypeDescription
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

OptionsType
(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:

  • collection mappings.
  • Elasticsearch index settings
  • reindexCollection (optional): if set to true, Kuzzle will reindex the collection after updating the mappings. This is useful when you want to update the mappings of a collection that already contains data.
const definition = {
  mappings: {
    properties: {
      field1: { type: "text" },
      field2: {
        properties: {
          nestedField: { type: "keyword" },
        },
      },
    },
  },
  reindexCollection: true,
  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:

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 #

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);
}