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.

mCreateOrReplace #

Creates or replaces multiple documents.

Throws a partial error (error code 206) if one or more document creations/replacements fail.

Signature #

Copied to clipboard!
std::string mCreateOrReplace(
    const std::string& index,
    const std::string& collection,
    const std::string& documents);

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

Arguments #

Argument Type Description
index
const std::string&
Index name
collection
const std::string&
Collection name
body
const std::string&
A JSON string containing the documents to create
options
kuzzleio::query_options*
Query options

options #

Additional query options

Option Type
(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 #

Returns an JSON string containing the created documents.

Exceptions #

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

Usage #

Copied to clipboard!
std::string documents = R"([
  {
    "_id": "some-id",
    "body": { "capacity": 4 }
  },
  {
    "_id": "some-other-id",
    "body": { "capacity": 4 }
  }
])";
try {
  std::string response = kuzzle->document->mCreateOrReplace(
    "nyc-open-data",
    "yellow-taxi",
    documents);
  std::cout << response << std::endl;
  /*
  [
    {
      "_id":"some-id",
      "_source":{
        "_kuzzle_info":{
          "active":true,
          "author":"-1",
          "updater":null,
          "updatedAt":null,
          "deletedAt":null,
          "createdAt":1538552685790
        },
        "capacity":4
      },
      "_index":"nyc-open-data",
      "_type":"yellow-taxi",
      "_version":1,
      "result":"created",
      "_shards":{
        "total":2,
        "successful":1,
        "failed":0
      },
      "created":true,
      "status":201
    },
    {
      "_id":"some-other-id",
      "_source":{
        "_kuzzle_info":{
          "active":true,
          "author":"-1",
          "updater":null,
          "updatedAt":null,
          "deletedAt":null,
          "createdAt":1538552685790
        },
        "capacity":4
      },
      "_index":"nyc-open-data",
      "_type":"yellow-taxi",
      "_version":1,
      "result":"created",
      "_shards":{
        "total":2,
        "successful":1,
        "failed":0
      },
      "created":true,
      "status":201
    }
  ]
  */
  std::cout << "Document successfully created" << std::endl;
} catch (kuzzleio::KuzzleException& e) {
  std::cerr << e.what() << std::endl;
}