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.
Signature #
void create(const std::string& index, const std::string& collection);
void create(
const std::string& index,
const std::string& collection,
const kuzzleio::query_options& options);
void create(
const std::string& index,
const std::string& collection,
const std::string& mapping);
void create(
const std::string& index,
const std::string& collection,
const std::string& mapping,
const kuzzleio::query_options& options);
Arguments #
Arguments | Type | Description |
---|---|---|
index | const std::string& | Index name |
collection | const std::string& | Collection name |
mapping | const std::string* | JSON string representing the collection data mapping |
options | kuzzleio::query_options* | Query options |
mapping #
A JSON string representing the collection data mapping.
The mapping must have a root field properties
that contain the mapping definition:
{
"properties": {
"field1": { "type": "text" },
"field2": {
"properties": {
"nestedField": { "type": "keyword" }
}
}
}
}
More informations about database mappings here.
options #
Additional query options
Property | Type (default) | Description |
---|---|---|
queuable | bool ( true ) | If true, queues the request during downtime, until connected to Kuzzle again |
Exceptions #
Throws a kuzzleio::KuzzleException
if there is an error. See how to handle error.
Usage #
try {
std::string mapping = R"({
"properties": {
"license": { "type": "keyword" },
"driver": {
"properties": {
"name": { "type": "keyword" },
"curriculum": { "type": "text" }
}
}
}
})";
kuzzle->collection->create("nyc-open-data", "yellow-taxi", mapping);
std::cout << "Collection successfully created" << std::endl;
} catch (kuzzleio::KuzzleException &e) {
std::cerr << e.what() << std::endl;
}