SDK
SDK Javascript v7.x
2

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:


write (index, collection, document, [id], [options])

ArgumentTypeDescription
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

PropertyType
(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.

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