SDK
SDK C++ v1.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.

This SDK has been deprecated because of stability issues. It is not advised to use it in a production environment.

mReplace #

Replaces multiple documents.

Throws a partial error (error code 206) if one or more documents can not be replaced.

Signature #

std::string mReplace(
    const std::string& index,
    const std::string& collection,
    const std::string& documents);

std::string mReplace(
    const std::string& index,
    const std::string& collection,
    const std::string& documents,
    const kuzzleio::query_options& options);

Arguments #

ArgumentTypeDescription
index
const std::string&
Index name
collection
const std::string&
Collection name
documents
const std::string&
JSON string representing the documents to replace
options
kuzzleio::query_options*
Query options

options #

Additional query options

OptionType
(default)
Description
queuable
bool

(true)
If true, queues the request during downtime, until connected to Kuzzle again
refresh
const std::string&
("")
If set to wait_for, waits for the change to be reflected for search (up to 1s)

Return #

A JSON string representing an object containing the following properties:

PropertyTypeDescription
hits
object[]
Array of replaced documents
total
number
Total documents replaced

Exceptions #

Throws a kuzzleio::KuzzleException if there is an error. See how to handle errors.

Usage #

try {
  kuzzle->document->create("nyc-open-data", "yellow-taxi", "some-id", "{}");
  kuzzle->document->create("nyc-open-data", "yellow-taxi", "some-other-id", "{}");
  std::string documents = R"(
    [
      {
        "_id": "some-id",
        "body": {"capacity": 4}
      },
      {
        "_id": "some-other-id",
        "body": {"capacity": 4}
      }
    ]
  )";
  std::string response = kuzzle->document->mReplace(
    "nyc-open-data",
    "yellow-taxi",
    documents);
  std::cout << response << std::endl;
    /*
      {  hits:
        [ { _id: 'some-id',
          _source:
            { _kuzzle_info:
              { active: true,
                author: '-1',
                updater: null,
                updatedAt: null,
                deletedAt: null,
                createdAt: 1538639586995 },
              capacity: 4 },
          _index: 'nyc-open-data',
          _type: 'yellow-taxi',
          _version: 2,
          result: 'updated',
          _shards: { total: 2, successful: 1, failed: 0 },
          created: false,
          status: 200 },
        { _id: 'some-other-id',
          _source:
            { _kuzzle_info:
              { active: true,
                author: '-1',
                updater: null,
                updatedAt: null,
                deletedAt: null,
                createdAt: 1538639586995 },
              capacity: 4 },
          _index: 'nyc-open-data',
          _type: 'yellow-taxi',
          _version: 2,
          result: 'updated',
          _shards: { total: 2, successful: 1, failed: 0 },
          created: false,
          status: 200 } ],
      total: 2 }
  */
  std::cout << "Successfully replaced 2 documents" << std::endl;
} catch (kuzzleio::KuzzleException& e) {
  std::cerr << e.what() << std::endl;
}