create #
Creates a new document in the persistent data storage.
Throws an error if the document already exists.
The optional parameter waitForRefresh
can be used with the value true
in order to wait for the document to be indexed (indexed documents are available for search
).
Arguments #
public CompletableFuture<ConcurrentHashMap<String, Object>> create(
final String index,
final String collection,
final ConcurrentHashMap<String, Object> document)
throws NotConnectedException, InternalException
public CompletableFuture<ConcurrentHashMap<String, Object>> create(
final String index,
final String collection,
final ConcurrentHashMap<String, Object> document,
final CreateOptions options)
throws NotConnectedException, InternalException
Arguments | Type | Description |
---|---|---|
index | String | Index |
collection | String | Collection |
document | ConcurrentHashMap<String, Object> | Document content |
options | CreateOptions ( null ) | Create options |
options #
A CreateOptions object.
The following options can be set:
Arguments | Type | Description |
---|---|---|
id | String(optional) | Document identifier. Auto-generated if not specified |
waitForRefresh | Boolean(optional) | If set to true , Kuzzle will wait for the persistence layer to finish indexing |
Return #
A ConcurrentHashMap
which has the following properties:
Property | Type | Description |
---|---|---|
_source | ConcurrentHashMap | Created document |
_id | String | ID of the newly created document |
_version | Integer | Version of the document in the persistent data storage |
Usage #
ConcurrentHashMap<String, Object> document = new ConcurrentHashMap<>();
document.put("firstname", "John");
ConcurrentHashMap<String, Object> result = kuzzle.getDocumentController().create("nyc-open-data", "yellow-taxi", document)
.get();
/* result =
{
_source=
{
firstname=John,
_kuzzle_info={ createdAt=1582891678488, author=-1 }
},
_id=mDmyi3ABYMAjFJ_ZO-EZ,
_version=1
}
*/
Edit this page on Github(opens new window)