write #
Available since 6.2.0
Available since Kuzzle 1.8.0
Creates or replaces a document directly into the storage engine.
This is a low level route intended to bypass Kuzzle actions on document creation, notably:
- check document validity,
- add kuzzle metadata,
- trigger realtime notifications (unless asked otherwise).
write (index, collection, document, [id], [options])
Argument | Type | Description |
---|---|---|
index | string | Index name |
collection | string | Collection name |
document | object | Document content |
id | string | Optional document ID |
options | object | Query options |
options #
Additional query options
Property | Type (default) | Description |
---|---|---|
queuable | boolean ( true ) | If true , queues the request during downtime, until connected to Kuzzle again |
notify | boolean ( false ) | if set to true , Kuzzle will trigger realtime notifications |
refresh | string ( "" ) | If set to wait_for , waits for the change to be reflected for search (up to 1s) |
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 to an object containing the document creation result.
Name | Type | Description |
---|---|---|
_id | string | ID of the newly created document |
_version | number | Version of the document in the persistent data storage |
_source | object | Created document |
Usage #
try {
const document = {
licence: 'B',
_kuzzle_info: {
creator: 'liia',
createdAt: 653132233
}
};
const result = await kuzzle.bulk.write(
'nyc-open-data',
'yellow-taxi',
document
);
console.log(result);
/*
{ _id: 'AWvljct6E7sKlamkyoHl',
_version: 1,
_source:
{ licence: 'B',
_kuzzle_info: { creator: 'liia', createdAt: 653132233 } }
*/
console.log(`Document creator is ${result._source._kuzzle_info.creator}`);
} catch (error) {
console.error(error.message);
}
Edit this page on Github(opens new window)