SDK
SDK Jvm v1.x
2

mCreate #

Creates multiple documents.


:::: tabs ::: tab Java

Arguments #

public CompletableFuture<Map<String, ArrayList<Object>>> mCreate(
      String index,
      String collection,
      ArrayList<Map<String, Object>> documents)
throws NotConnectedException, InternalException

public CompletableFuture<Map<String, ArrayList<Object>>> mCreate(
      String index,
      String collection,
      ArrayList<Map<String, Object>> documents,
      Boolean waitForRefresh)
throws NotConnectedException, InternalException
ArgumentsTypeDescription
index
String
Index
collection
String
Collection
documents
ArrayList<Map<String, Object>>
ArrayList containing the documents to create
waitForRefresh
Boolean
If set to true, Kuzzle will wait for the persistence layer to finish indexing

documents #

Each document has the following properties:

ArgumentsTypeDescription
_id
String
Optional document ID. Will be auto-generated if not defined.
body
Map<String, Object>
Document body

Return #

A Map<String, ArrayList<Object>> which has a successes and errors ArrayList<Object>: Each created document is an object of the successes array with the following properties:

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

Each errored document is an object of the errors array with the following properties:

PropertyTypeDescription
document
Map<String, Object>
Document that causes the error
status
Integer
HTTP error status
reason
String
Human readable reason

Usage #

Map<String, Object> document1 = new HashMap<>();
Map<String, Object> document2 = new HashMap<>();
Map<String, Object> body = new HashMap<>();
Map<String, Object> body2 = new HashMap<>();
body.put("Agent", "Smith");
body2.put("Gordon", "Freeman");
document1.put("_id", "some-id");
document1.put("body", body);
document2.put("_id", "some-id2");
document2.put("body", body2);
final ArrayList<Map<String, Object>> documents = new ArrayList<>();
documents.add(document1);
documents.add(document2);
Map<String, ArrayList<Object>> result = kuzzle
  .getDocumentController()
  .mCreate("nyc-open-data", "yellow-taxi", documents)
  .get();
/*
result =
  {
    successes=
    [
      {
        result=created,
        _source=
          {
            Agent=Smith,
            _kuzzle_info={createdAt=1582892842099, author=-1}
          },
        _id=some-id,
        _version=1,
        status=201
      },
      {
        result=created,
        _source=
          {
            Gordon=Freeman,
            _kuzzle_info={createdAt=1582892842099, author=-1}
          },
        _id=some-id2,
        _version=1,
        status=201
      }
    ],
    errors=[]
  }
*/

::: ::: tab Kotlin

Arguments #

fun mCreate(
      index: String,
      collection: String,
      documents: ArrayList<Map<String, Any?>>,
      waitForRefresh: Boolean? = null): CompletableFuture<Map<String, ArrayList<Any>>>
ArgumentsTypeDescription
index
String
Index
collection
String
Collection
documents
ArrayList<Map<String, Any?>>
ArrayList containing the documents to create
waitForRefresh
Boolean
If set to true, Kuzzle will wait for the persistence layer to finish indexing

documents #

Each document has the following properties:

ArgumentsTypeDescription
_id
String
Optional document ID. Will be auto-generated if not defined.
body
Map<String, Any?>
Document body

Return #

A Map<String, ArrayList<Object>> which has a successes and errors ArrayList<Object>: Each created document is an object of the successes array with the following properties:

PropertyTypeDescription
_source
Map<String, Any?>
Created document
_id
String
ID of the newly created document
_version
Int
Version of the document in the persistent data storage

Each errored document is an object of the errors array with the following properties:

PropertyTypeDescription
document
Map<String, Any?>
Document that causes the error
status
Integer
HTTP error status
reason
String
Human readable reason

Usage #

val document1: Map<String, Any?> =
  HashMap<String, Any?>().apply {
    put("_id", "some-id")
    put("body", HashMap<String, Any?>().apply {
      put("Agent", "Smith")
    })
  }
val document2: Map<String, Any?> =
  HashMap<String, Any?>().apply {
    put("_id", "some-id2")
    put("body", HashMap<String, Any?>().apply {
      put("Gordon", "Freeman")
    })
  }
val documents: ArrayList<Map<String, Any?>> =
  ArrayList<Map<String, Any?>>().apply {
    add(document1)
    add(document2)
  }
val result: Map<String, ArrayList<Any>> =
  kuzzle
    .documentController
    .mCreateOrReplace("nyc-open-data", "yellow-taxi", documents)
    .get()

::: ::::