SDK
SDK C# v1.x
1

# MCreateOrReplaceAsync

Creates or replaces multiple documents.

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

# Arguments

Copied to clipboard!
public async Task<JArray> 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

A JArray representing the created 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 created or replaced.

# 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 {
  JArray response = await kuzzle.Document.MCreateOrReplaceAsync(
    "nyc-open-data",
    "yellow-taxi",
    documents);
  Console.WriteLine(response.ToString());
  /*
  [
    {
      "_id":"some-id",
      "_source":{
        "_kuzzle_info":{
          "active":true,
          "author":"-1",
          "updater":null,
          "updatedAt":null,
          "deletedAt":null,
          "createdAt":1538552685790
        },
        "capacity":4
      },
      "_version":1,
      "result":"created",
      "status":201
    },
    {
      "_id":"some-other-id",
      "_source":{
        "_kuzzle_info":{
          "active":true,
          "author":"-1",
          "updater":null,
          "updatedAt":null,
          "deletedAt":null,
          "createdAt":1538552685790
        },
        "capacity":4
      },
      "_version":1,
      "result":"created",
      "status":201
    }
  ]
  */
  Console.WriteLine($"Successfully created {response.Count} documents");
} catch (KuzzleException e) {
  Console.Error.WriteLine(e);
}