SDK
SDK C# v2.x
2

CreateAsync #

Creates a new collection in the provided index. You can also provide an optional body with a collection mapping allowing you to exploit the full capabilities of our persistent data storage layer.

This method will only update the mapping if the collection already exists.

Arguments #

Copied to clipboard!
public async Task CreateAsync(
        string index,
        string collection,
        JObject mappings = null);
Argument Type Description
index
string
Index name
collection
string
Collection name
mapping
JObject

(null)
JObject representing the collection data mapping

mapping #

A JObject representing the collection data mapping.

The mapping must have a root field properties containing the mapping definition:

Copied to clipboard!
{
  "properties": {
    "field1": { "type": "text" },
    "field2": {
      "properties": {
        "nestedField": { "type": "keyword" }
      }
    }
  }
}

More information about database mappings here.

Exceptions #

Throws a KuzzleException if there is an error. See how to handle error.

Usage #

Copied to clipboard!
try {
  JObject mapping = JObject.Parse(@"
  {
    properties: {
      license: { type: 'keyword' },
      driver: {
        properties: {
          name: { type: 'keyword' },
          curriculum: { type: 'text' }
        }
      }
    }
  }");
  await kuzzle.Collection.CreateAsync("nyc-open-data", "yellow-taxi", mapping);
  Console.WriteLine("Collection successfully created");
} catch (Exception e) {
  Console.WriteLine(e);
}