SDK
SDK Java v3.x
2

This SDK is deprecated. We recommend to use the Kuzzle SDK-JVM.
A migration guide is available here

mCreateOrReplace #

Creates or replaces multiple documents.


Arguments #

public CompletableFuture<ConcurrentHashMap<String, ArrayList<Object>>> mCreateOrReplace(
      final String index,
      final String collection,
      final ArrayList<ConcurrentHashMap<String, Object>> documents)
throws NotConnectedException, InternalException

public CompletableFuture<ConcurrentHashMap<String, ArrayList<Object>>> mCreateOrReplace(
      final String index,
      final String collection,
      final ArrayList<ConcurrentHashMap<String, Object>> documents,
      final Boolean waitForRefresh)
throws NotConnectedException, InternalException
ArgumentsTypeDescription
index
String
Index
collection
String
Collection
documents
ArrayList<ConcurrentHashMap<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
ConcurrentHashMap<String, Object>
Document body

Return #

A ConcurrentHashMap<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
ConcurrentHashMap<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
ConcurrentHashMap<String, Object>
Document that causes the error
status
Integer
HTTP error status
reason
String
Human readable reason

Usage #

ConcurrentHashMap<String, Object> document1 = new ConcurrentHashMap<>();
ConcurrentHashMap<String, Object> document2 = new ConcurrentHashMap<>();
ConcurrentHashMap<String, Object> body = new ConcurrentHashMap<>();
ConcurrentHashMap<String, Object> body2 = new ConcurrentHashMap<>();
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<ConcurrentHashMap<String, Object>> documents = new ArrayList<>();
documents.add(document1);
documents.add(document2);
ConcurrentHashMap<String, ArrayList<Object>> result = kuzzle
  .getDocumentController()
  .mCreateOrReplace("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=[]
  }
*/