SDK
SDK Javascript v6.x
1

You are currently looking at the documentation of a previous version of Kuzzle. We strongly recommend that you use the latest version. You can also use the version selector in the top menu.

create #

Creates a new collection in Kuzzle via the persistence engine, in the provided index.

You can also provide an optional data mapping that allow you to exploit the full capabilities of our persistent data storage layer, ElasticSearch (check here the mapping capabilities of ElasticSearch).

This method will only update the mapping if the collection already exists.


create(index, collection, [mapping], [options]);

ArgumentsTypeDescription
index
string
Index name
collection
string
Collection name
mapping
object
Describes the data mapping to associate to the new collection, using Elasticsearch mapping format
options
object
Query options

mapping #

An object representing the data mapping of the collection.

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

const mapping = {
  properties: {
    field1: { type: 'text' },
    field2: {
      properties: {
        nestedField: { type: 'keyword' }
      }
    }
  }
};

More informations about database mappings here.

options #

Additional query options

PropertyType
(default)
Description
queuable
boolean

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

Resolves #

Resolves if the collection is successfully created.

Usage #

const mapping = {
  properties: {
    license: { type: 'keyword' },
    driver: {
      properties: {
        name: { type: 'keyword' },
        curriculum: { type: 'text' }
      }
    }
  }
};
try {
  await kuzzle.collection.create('nyc-open-data', 'yellow-taxi', mapping);
  console.log('Success');
} catch (error) {
  console.error(error.message);
}