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 #
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:
- collection mappings.
- Elasticsearch index settings The mappings must have a root field
properties
that contain the mapping definition:
{
"mappings"= {
"properties"= {
"field1"= { "type"= "text" },
"field2"= {
"properties"= {
"nestedField"= { "type"= "keyword" }
}
}
}
},
"settings"= {
}
};
Usage #
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 #
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 #
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()
::: ::::
Edit this page on Github(opens new window)