create #
Creates a new collection 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.
Available since Kuzzle 2.2.0
Available since 7.4.0
You can also provide Elasticsearch index settings when creating a new collection.
create(index, collection, [definition], [options]);
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
definition #
An object containings:
- collection mappings.
- Elasticsearch index settings The mapping must have a root field
properties
that contain the mapping definition:
const definition = {
mappings: {
properties: {
field1: { type: 'text' },
field2: {
properties: {
nestedField: { type: 'keyword' }
}
}
}
},
settings: {
}
};
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.
options #
Additional query options
Property | Type (default) | Description |
---|---|---|
queuable | boolean ( true ) | If true , queues the request during downtime, until connected to Kuzzle again |
timeout | number ( -1 ) | Time (in ms) during which a request will still be waited to be resolved. Set it -1 if you want to wait indefinitely |
triggerEvents | boolean ( false ) | If set to true , will trigger events even if using Embeded SDK. You should always ensure that your events/pipes does not create an infinite loop. Available since Kuzzle 2.31.0 |
Resolves #
Resolves if the collection is successfully created.
Usage #
const mappings = {
properties: {
license: { type: 'keyword' },
driver: {
properties: {
name: { type: 'keyword' },
curriculum: { type: 'text' }
}
}
}
};
try {
await kuzzle.collection.create('nyc-open-data', 'yellow-taxi', { mappings });
console.log('Success');
} catch (error) {
console.error(error.message);
}
Edit this page on Github(opens new window)