SDK
SDK Javascript v7.x
2

replace #

Replaces the content of an existing document.


Copied to clipboard!
replace(index, collection, id, document, [options]);
Argument Type Description
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

Options Type
(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.

Name Type Description
_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 #

Copied to clipboard!
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);
  /*
  { _id: 'some-id',
    _version: 2,
    _source:
    { capacity: 4,
      category: 'sedan',
      _kuzzle_info:
        { author: '-1',
          createdAt: 1538654776456,
          updatedAt: 1538654776456,
          updater: '-1' } } }
  */
  console.log('Success');
} catch (error) {
  console.error(error.message);
}