MReplaceAsync

Replaces multiple documents.

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

Arguments

Copied to clipboard!
public async Task<JArray> MReplaceAsync(
  string index,
  string collection,
  JArray documents,
  bool waitForRefresh = false);


Argument Type Description
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:

Property Type Description
_id
string
Document ID
body
JObject
Document content

Return

A JArray representing the replaced documents.

Each document has the following properties:

Property Type Description
_id
string
ID of the newly created document
_version
int
Version of the document in the persistent data storage
_source
JObject
JObject representing the created document
result
string
Set to replaced.

Exceptions

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

Usage

Copied to clipboard!
try {
  JArray documents = JArray.Parse(@"
    [
      {
        ""_id"": ""some-id"",
        ""body"": {""capacity"": 4}
      },
      {
        ""_id"": ""some-other-id"",
        ""body"": {""capacity"": 4}
      }
    ]
  ");

  JArray response = await kuzzle.Document.MReplaceAsync(
    "nyc-open-data",
    "yellow-taxi",
    documents);

  Console.WriteLine(response.ToString());
    /*
      {  hits:
        [ { _id: 'some-id',
          _source:
            { _kuzzle_info:
              { active: true,
                author: '-1',
                updater: null,
                updatedAt: null,
                deletedAt: null,
                createdAt: 1538639586995 },
              capacity: 4 },
          _version: 2,
          result: 'replaced',
          status: 200 },
        { _id: 'some-other-id',
          _source:
            { _kuzzle_info:
              { active: true,
                author: '-1',
                updater: null,
                updatedAt: null,
                deletedAt: null,
                createdAt: 1538639586995 },
              capacity: 4 },
          _version: 2,
          result: 'replaced',
          status: 200 } ],
      total: 2 }
  */

  Console.WriteLine($"Successfully replaced {response.Count} documents");
} catch (KuzzleException e) {
  Console.Error.WriteLine(e);
}