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.

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)

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