MCreateAsync #
Creates multiple documents.
Arguments #
public async Task<JObject> 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 #
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 |
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 #
JArray documents = JArray.Parse(@"[
{
""_id"": ""some-id"",
""body"": { ""capacity"": 4 }
},
{
""body"": { ""this"": ""document id is auto-computed"" }
}
]");
try {
JObject response = await kuzzle.Document.MCreateAsync(
"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":"AWY0AoLgKWETYfLdcMat",
"_source":{
"_kuzzle_info":{
"active":true,
"author":"-1",
"updater":null,
"updatedAt":null
},
"this":"document id is auto-computed"
},
"_version":1
}
],
"errors": []
}
*/
Console.WriteLine($"Successfully created {((JArray)response["successes"]).Count} documents");
} catch (KuzzleException e) {
Console.Error.WriteLine(e);
}
Edit this page on Github(opens new window)