Create

Creates a new collection in the provided index. You can also provide an optional data mapping that allow you to exploit the full capabilities of our persistent data storage layer, ElasticSearch (check here the mapping capabilities of ElasticSearch).

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

Arguments

Copied to clipboard!
Create(index string, collection string, mapping json.RawMessage, options types.QueryOptions) error
Arguments Type Description
index
string
Index name
collection
string
Collection name
mapping
json.RawMessage
Collection data mapping in JSON format
options
QueryOptions
Query options

mapping

An string containing the JSON representation of the collection data mapping.

The mapping must have a root field properties that contain the mapping definition:

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

More informations about database mappings here.

options

Additional query options

Property Type Description Default
queuable
bool
Make this request queuable or not true

Return

Return an error or nil if collection successfully created.

Usage

Copied to clipboard!
mapping := json.RawMessage(`{"properties":{"license": {"type": "text"}}}`)
err := kuzzle.Collection.Create("nyc-open-data", "yellow-taxi", mapping, nil)

if err != nil {
  log.Fatal(err)
} else {
  fmt.Println("Success")
}