SDK
SDK C# v2.x
2

CreateOrReplaceAsync #

Creates a new document in the persistent data storage, or replaces its content if it already exists.

Arguments #

public async Task<JObject> CreateOrReplaceAsync( 
  string index, 
  string collection, 
  string id, 
  JObject content, 
  bool waitForRefresh = false);

ArgumentTypeDescription
index
string
Index name
collection
string
Collection name
id
string

Document ID
content
JObject
JObject representing the body of the document
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.

PropertyTypeDescription
_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 #

try {
  JObject result = await kuzzle.Document.CreateOrReplaceAsync(
    "nyc-open-data",
    "yellow-taxi",
    "some-id",
    JObject.Parse(@"{
      ""lastName"": ""McHan""
    }"));
  Console.WriteLine(result.ToString());
  /*
  {
    "_id": "some-id",
    "_version": 1,
    "result": "created",
    "_source": {
      "lastName": "McHan",
      "_kuzzle_info": {
        "author": "-1",
        "createdAt": 1537445737667,
        "updatedAt": null,
        "updater": null
      }
    }
  }
  */
  Console.WriteLine("Document successfully created");
} catch (KuzzleException e) {
  Console.Error.WriteLine(e);
}