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.

replace #

Replaces the content of an existing document.


replace(index, collection, id, document, [options]);
ArgumentTypeDescription
index
string
Index name
collection
string
Collection name
id
string
Document ID
document
object
New content of the document to update
options
object
Query options

Options #

Additional query options

OptionsType
(default)
Description
queuable
boolean

(true)
If true, queues the request during downtime, until connected to Kuzzle again
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 the document update result.

NameTypeDescription
_id
string
ID of the newly created document
_version
number
Version of the document in the persistent data storage
_source
object
The updated document

Usage #

const doc = { color: 'yellow' };
try {
  await kuzzle.document.create('nyc-open-data', 'yellow-taxi', doc, 'some-id');
  const response = await kuzzle.document.replace(
    'nyc-open-data',
    'yellow-taxi',
    'some-id',
    { capacity: 4, category: 'sedan' }
  );
  console.log(response);
  /*
  { _index: 'nyc-open-data',
  _type: 'yellow-taxi',
  _id: 'some-id',
  _version: 2,
  result: 'updated',
  _shards: { total: 2, successful: 1, failed: 0 },
  created: false,
  _source:
    { capacity: 4,
      category: 'sedan',
      _kuzzle_info:
        { author: '-1',
          createdAt: 1538654776456,
          updatedAt: 1538654776456,
          updater: '-1',
          active: true,
          deletedAt: null } } }
  */
  console.log('Success');
} catch (error) {
  console.error(error.message);
}