SDK
SDK Jvm v1.x
2

createOrReplace #

Creates a new document in the persistent data storage, or replaces its content if it already exists.


:::: tabs ::: tab Java

Arguments #

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

public CompletableFuture<Map<String, Object>> createOrReplace(
      String index,
      String collection,
      String id,
      Map<String, Object> document,
      Boolean waitForRefresh)
throws NotConnectedException, InternalException
ArgumentsTypeDescription
index
String
Index
collection
String
Collection
id
String
Document ID
document
Map<String, Object>
Document content
waitForRefresh
Boolean
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
Document content
_id
String
ID of the 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()
  .createOrReplace("nyc-open-data", "yellow-taxi", "some-id", document)
  .get();
/*
  {
    _source=
      {
        firstname=John,
        _kuzzle_info={ 
          createdAt=1582892323254, 
          author=-1, 
          updatedAt=1582892323254, 
          updater=-1
        }
      },
  _id=some-id,
  _version=1
  }
 */

::: ::: tab Kotlin

Arguments #

fun createOrReplace(
  index: String,
  collection: String,
  id: String,
  document: Map<String, Any?>,
  waitForRefresh: Boolean? = null): CompletableFuture<Map<String, Any?>>
ArgumentsTypeDescription
index
String
Index
collection
String
Collection
id
String
Document ID
document
Map<String, Any?>
Document content
waitForRefresh
Boolean

(null)
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
Document content
_id
String
ID of the 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
    .createOrReplace("nyc-open-data", "yellow-taxi", "some-id", document)
    .get()

::: ::::