create #
Creates a new collection in the provided index
.
Available since 1.3.0
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.
create([mapping], [options], [callback]) #
Arguments | Type | Description |
---|---|---|
mapping | JSON Object | Optional data mapping |
options | JSON Object | Optional parameters |
callback | function | Optional callback |
Options #
Option | Type | Description | Default |
---|---|---|---|
queuable | boolean | Make this request queuable or not | true |
Return Ralue #
Returns the Collection
object to allow chaining.
Callback Response #
Returns a JSON object
containing the raw Kuzzle response.
Usage #
// Optional: a mapping can be provided and will be
// applied when the collection is created
JSONObject mapping = new JSONObject()
.put("properties", new JSONObject()
.put("field1", new JSONObject().put("type", "<es field type>"))
.put("field2", new JSONObject().put("type", "<es field type>"))
);
kuzzle
.collection("collection", "index")
.create(mapping, new ResponseListener<JSONObject>() {
@Override
public void onSuccess(JSONObject object) {
// callback called once the create operation has completed
// => the result is a JSON object containing the raw Kuzzle response:
// {
// acknowledged: true
// }
}
@Override
public void onError(JSONObject error) {
// Handle error
}
});
Callback response:
{
"status": 200,
"error": null,
"requestId": "<request unique identifier>",
"controller": "collection",
"action": "create",
"collection": "<new collection name>",
"index": "index",
"volatile": null,
"result": {
"acknowledged": true
}
}
Edit this page on Github(opens new window)