Unknown SDK

MCreateAsync

Creates multiple documents.

Throws a partial error (error code 206) if one or more documents creations fail.

Arguments

Copied to clipboard!
public async Task<JArray> MCreateAsync(
  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
Optional document ID. Will be auto-generated if not defined.
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 in case of success

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 }
  },
  {
    ""body"": { ""this"": ""document id is auto-computed"" }
  }
]");
try {
  JArray response = await kuzzle.Document.MCreateAsync(
    "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":1538470871764
        },
        "capacity":4
      },
      "_version":1,
      "result":"created",
      "status":201
    },
    {
      "_id":"AWY0AoLgKWETYfLdcMat",
      "_source":{
        "_kuzzle_info":{
          "active":true,
          "author":"-1",
          "updater":null,
          "updatedAt":null,
          "deletedAt":null,
          "createdAt":1538470871764
        },
        "this":"document id is auto-computed"
      },
      "_version":1,
      "result":"created",
      "status":201
    }
  ]
  */
  Console.WriteLine($"Successfully created {response.Count} documents");
} catch (KuzzleException e) {
  Console.Error.WriteLine(e);
}