SDK
SDK Jvm v1.x
2

create #

Creates a new collection in Kuzzle via the persistence engine, in the provided index.

You can also provide optional data mappings that allow you to exploit the full capabilities of our persistent data storage layer, ElasticSearch (check here the mappings capabilities of ElasticSearch).

This method will only update the mappings and/or the settings if the collection already exists.


:::: tabs ::: tab Java

Arguments #

Copied to clipboard!
public CompletableFuture<Void> create(
      final String index,
      final String collection,
      final Map<String, Object> definition)
throws NotConnectedException, InternalException

public CompletableFuture<Void> create(
      final String index,
      final String collection)
throws NotConnectedException, InternalException
Arguments Type Description
index
String
Index
collection
String
Collection
definition
Map<String, Object>
Describes the collection mappings and the ES index settings

definition #

An object containing:

Copied to clipboard!
{
  "mappings"= {
    "properties"= {
      "field1"= { "type"= "text" },
      "field2"= {
        "properties"= {
          "nestedField"= { "type"= "keyword" }
        }
      }
    }    
  },
  "settings"= {

  }
};

Usage #

Copied to clipboard!
Map<String, Object> definition = new HashMap<>();
Map<String, Object> mappings = new HashMap<>();
Map<String, Object> properties = new HashMap<>();
Map<String, Object> license = new HashMap<>();
license.put("type", "keyword");
properties.put("license", license);
mappings.put("properties", properties);
definition.put("mappings", mappings);
kuzzle.getCollectionController().create("nyc-open-data", "yellow-taxi", definition)
  .get();

::: ::: tab Kotlin

Arguments #

Copied to clipboard!
fun create(
      index: String,
      collection: String,
      definition: Map<String, Any>?
    ): CompletableFuture<Void>
Arguments Type Description
index
String
Index
collection
String
Collection
definition
Map<String, Any>?
Describes the collection mappings and the ES index settings

Usage #

Copied to clipboard!
val type: Map<String, Any> = HashMap<String, Any>().apply {
  put("type", "keyword")
}
val license: Map<String, Any> = HashMap<String, Any>().apply {
  put("license", type)
}
val mappings: Map<String, Any> = HashMap<String, Any>().apply {
  put("properties", license)
}
val definition: Map<String, Any> = HashMap<String, Any>().apply {
  put("mappings", mappings)
}
kuzzle.collectionController.create(
  "nyc-open-data",
  "yellow-taxi",
  definition
).get()

::: ::::