MCreateOrReplaceAsync

Creates or replaces multiple documents.

Arguments

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


Argument Type Description
index
string
Index name
collection
string
Collection name
documents
JArray
A JArray containing the documents to create
waitForRefresh
bool

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

documents

Each document has the following properties:

Property Type Description
_id
string
Document ID
body
JObject
Document body

Return

Returns a JObject containing 2 arrays: successes and errors

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

Name Type Description
_id
String
Document ID
_version
int
Version of the document in the persistent data storage
_source
JObject
Document content
result
String
Set to created or replaced.

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

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

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