CreateAsync #
Creates a new document in the persistent data storage.
Throws an error if an ID is provided and if a document with that ID already exists.
Arguments #
public async Task<JObject> CreateAsync(
string index,
string collection,
JObject content,
string id = null,
bool waitForRefresh = false);
Option | Type (default) | Description |
---|---|---|
index | string | Index name |
collection | string | Collection name |
content | JObject | JObject representing the body of the document |
id | string ( null ) | Document ID. Will use an auto-generated ID if not specified |
waitForRefresh | bool ( false ) | If true , waits for the change to be reflected for search (up to 1s) |
Return #
A JObject containing the document creation result.
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 #
try {
JObject result = await kuzzle.Document.CreateAsync(
"nyc-open-data",
"yellow-taxi",
JObject.Parse(@"{
""lastname"": ""Eggins""
}"),
id: "some-id");
Console.WriteLine(result.ToString());
/*
{
"_id": "some-id",
"_version": 1,
"_source": {
"lastName": "Eggins",
"_kuzzle_info": {
"author": "-1",
"createdAt": 1537445737667,
"updatedAt": null,
"updater": null
}
}
}
*/
Console.WriteLine("Document successfully created");
} catch (KuzzleException e) {
Console.Error.WriteLine(e);
}
Edit this page on Github(opens new window)