SDK
SDK C# v2.x
2

MReplaceAsync #

Replaces multiple documents.

Arguments #

public async Task<JObject> MReplaceAsync(
  string index,
  string collection,
  JArray documents,
  bool waitForRefresh = false);

ArgumentTypeDescription
index
string
Index name
collection
string
Collection name
documents
JArray
Array of JObject instances, each representing a document to replace
waitForRefresh
bool

(false)
If true, waits for the change to be reflected for search (up to 1s)

documents #

Array of documents, each one with the following expected properties:

PropertyTypeDescription
_id
string
Document ID
body
JObject
Document content

Return #

Returns a JObject containing 2 arrays: successes and errors

Each replaced document is an object of the successes array with the following properties:

NameTypeDescription
_id
string
Document ID
_version
int
Version of the document in the persistent data storage
_source
JObject
Document content

Each errored document is an object of the errors array with the following properties:

NameTypeDescription
document
JObject
Document that cause the error
status
int
HTTP error status
reason
string
Human readable reason

Exceptions #

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

Usage #

try {
  JArray documents = JArray.Parse(@"
    [
      {
        ""_id"": ""some-id"",
        ""body"": {""capacity"": 4}
      },
      {
        ""_id"": ""some-other-id"",
        ""body"": {""capacity"": 4}
      }
    ]
  ");
  JObject response = await kuzzle.Document.MReplaceAsync(
    "nyc-open-data",
    "yellow-taxi",
    documents);
  Console.WriteLine(response.ToString());
    /*
    { successes:
      [ { _id: 'some-id',
        _version: 2,
        _source: {
          _kuzzle_info:
          { author: '-1',
            updater: null,
            updatedAt: null,
            createdAt: 1538639586995 },
          capacity: 4 }
      },
      [ { _id: 'some-other-id',
        _version: 2,
        _source: {
          _kuzzle_info:
          { author: '-1',
            updater: null,
            updatedAt: null,
            createdAt: 1538639586995 },
          capacity: 4 } ],
      errors: [] }
  */
  Console.WriteLine($"Successfully replaced {((JArray)response["successes"]).Count} documents");
} catch (KuzzleException e) {
  Console.Error.WriteLine(e);
}