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 #

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