SDK
SDK Jvm v1.x
2

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).


:::: tabs ::: tab Java

Arguments #

public CompletableFuture<Map<String, Object>> create(
      String index,
      String collection,
      Map<String, Object> document)
throws NotConnectedException, InternalException

public CompletableFuture<Map<String, Object>> create(
      String index,
      String collection,
      Map<String, Object> document,
      String id)
throws NotConnectedException, InternalException

public CompletableFuture<Map<String, Object>> create(
      String index,
      String collection,
      Map<String, Object> document,
      String id,
      Boolean waitForRefresh)
throws NotConnectedException, InternalException
ArgumentsTypeDescription
index
String
Index
collection
String
Collection
document
Map<String, Object>
Document content
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 Map which has the following properties:

PropertyTypeDescription
_source
Map
Created document
_id
String
ID of the newly created document
_version
Integer
Version of the document in the persistent data storage

Usage #

Map<String, Object> document = new HashMap<>();
document.put("firstname", "John");
Map<String, Object> result =
  kuzzle
    .getDocumentController()
    .create("nyc-open-data", "yellow-taxi", document)
    .get();

::: ::: tab Kotlin

Arguments #

fun create(
  index: String,
  collection: String,
  document: Map<String, Any?>,
  id: String? = null,
  waitForRefresh: Boolean? = null): CompletableFuture<Map<String, Any?>>
ArgumentsTypeDescription
index
String
Index
collection
String
Collection
document
Map<String, Any?>
Document content
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 Map which has the following properties:

PropertyTypeDescription
_source
Map
Created document
_id
String
ID of the newly created document
_version
Int
Version of the document in the persistent data storage

Usage #

val document: Map<String, Any?> = HashMap<String, Any?>().apply {
  put("firstname", "John")
}
val result: Map<String, Any?> =
  kuzzle
    .documentController
    .create("nyc-open-data", "yellow-taxi", document)
    .get()

::: ::::