SDK
SDK C# v1.x
1

You are currently looking at the documentation of a previous version of Kuzzle. We strongly recommend that you use the latest version. You can also use the version selector in the top menu.

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 #

public async Task CreateAsync(
        string index,
        string collection,
        JObject mappings = null);
ArgumentTypeDescription
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:

{
  "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 #

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);
}