SDK
SDK Jvm v1.x
2

importData #

Creates, updates or deletes large amounts of documents as fast as possible.

This route is faster than the document:m* routes family (e.g. document:mCreate), but no real-time notifications will be generated, even if some of the documents in the import match subscription filters.

:::: tabs ::: tab Java

Arguments #

public CompletableFuture<Map<String, Object>> importData(
    String index,
    String collection,
    ArrayList<Map<String, Object>> bulkData
) throws NotConnectedException, InternalException
ArgumentTypeDescription
index
String
Index name
collection
String
Collection name
bulkData
ArrayList<Map<String, Object>>
Bulk operations to perform, following ElasticSearch Bulk API

bulkData #

This API takes a JSON array containing a list of objects working in pairs. In each pair, the first object specifies the action to perform (the most common is create) and the second specifies the document itself, like in the example below:

[
  // Action object
  { "create": { "_id": "id" } },
  // Document object
  { "myField": "myValue", "myOtherField": "myOtherValue" },

  // Another action object
  { "create": { "_id": "another-id" } },
  // Another document object
  { "myField": "anotherValue", "myOtherField": "yetAnotherValue" }
];

Possible actions are create, index, update, delete.

Learn more at Elasticsearch Bulk API

Return #

A Map<String, Any?> containing 2 arrays:

PropertyTypeDescription
successes
ArrayList<Map<String, Object>>
Array of object containing successful document import
errors
ArrayList<Map<String, Object>>
Array of object containing failed document import

Each item of the successes array is an object containing the action name as key and the corresponding object contain the following properties:

PropertyTypeDescription
_id
String
Document unique identifier
status
Integer
HTTP status code for that query

Each item of the errors array is an object containing the action name as key and the corresponding object contain the following properties:

PropertyTypeDescription
_id
String
Document unique identifier
status
Integer
HTTP status code for that query
error
<Map<String, Object>
Error object

Each error object contain the following properties:

PropertyTypeDescription
type
String
Elasticsearch client error type
reason
String
human readable error message

Usage #

Map<String, Object> index = new HashMap<String, Object>();
index.put("index", new HashMap<String, Object>());
Map<String, Object> document = new HashMap<String, Object>();
document.put("a", "document");
document.put("with", "any");
document.put("number", "of fields");
Map<String, Object> id = new HashMap<String, Object>();
id.put("_id", "uniq-id-1");
Map<String, Object> create = new HashMap<String, Object>();
create.put("create", id);
Map<String, Object> document2 = new HashMap<String, Object>();
document2.put("another", "document");
Map<String, Object> id2 = new HashMap<String, Object>();
id2.put("_id", "uniq-id-2");
Map<String, Object> create2 = new HashMap<String, Object>();
create2.put("create", id2);
Map<String, Object> another = new HashMap<String, Object>();
id2.put("another", "one");
Map<String, Object> and = new HashMap<String, Object>();
create2.put("and", another);
ArrayList<Map<String, Object>> bulkData = new ArrayList<Map<String, Object>>();
bulkData.add(index);
bulkData.add(document);
bulkData.add(create);
bulkData.add(document2);
bulkData.add(create2);
bulkData.add(and);
Map<String, Object> result =
  kuzzle.getBulkController().importData(
    "nyc-open-data",
    "yellow-taxi",
    bulkData
  )
  .get();

::: ::: tab Kotlin

Arguments #

fun importData(
  index: String,
  collection: String,
  bulkData: ArrayList<Map<String, Any?>>
  ): CompletableFuture<Map<String, Any?>>
ArgumentTypeDescription
index
String
Index name
collection
String
Collection name
bulkData
ArrayList<Map<String, Any?>>
Bulk operations to perform, following ElasticSearch Bulk API

bulkData #

This API takes a JSON array containing a list of objects working in pairs. In each pair, the first object specifies the action to perform (the most common is create) and the second specifies the document itself, like in the example below:

[
  // Action object
  { "create": { "_id": "id" } },
  // Document object
  { "myField": "myValue", "myOtherField": "myOtherValue" },

  // Another action object
  { "create": { "_id": "another-id" } },
  // Another document object
  { "myField": "anotherValue", "myOtherField": "yetAnotherValue" }
];

Possible actions are create, index, update, delete.

Learn more at Elasticsearch Bulk API

Return #

A Map<String, Any?> containing 2 arrays:

PropertyTypeDescription
successes
ArrayList<Map<String, Any?>>
Array of object containing successful document import
errors
ArrayList<Map<String, Any?>>
Array of object containing failed document import

Each item of the successes array is an object containing the action name as key and the corresponding object contain the following properties:

PropertyTypeDescription
_id
String
Document unique identifier
status
Int
HTTP status code for that query

Each item of the errors array is an object containing the action name as key and the corresponding object contain the following properties:

PropertyTypeDescription
_id
String
Document unique identifier
status
Int
HTTP status code for that query
error
<Map<String, Any?>
Error object

Each error object contain the following properties:

PropertyTypeDescription
type
String
Elasticsearch client error type
reason
String
human readable error message

Usage #

val bulkData: ArrayList<Map<String, Any?>> = ArrayList<Map<String, Any?>>().apply {
  add(HashMap<String, Any?>().apply {
    put("index", HashMap<String, Any?>());
  });
  add(HashMap<String, Any?>().apply {
    put("a", "document");
    put("with", "any");
    put("number", "of fields");
  });
  add(HashMap<String, Any?>().apply {
    put("create", 
      HashMap<String, Any?>().apply {
        put("_id", "uniq-id-1");
      }
    );
  });
  add(HashMap<String, Any?>().apply {
    put("another", "document");
  });
  add(HashMap<String, Any?>().apply {
    put("create", 
      HashMap<String, Any?>().apply {
        put("_id", "uniq-id-2");
      }
    );
  });
  add(HashMap<String, Any?>().apply {
    put("and", 
      HashMap<String, Any?>().apply {
        put("another", "one");
      }
    );
  });
};
val result: Map<String, Any?> =
  kuzzle.bulkController.importData(
    "nyc-open-data",
    "yellow-taxi",
    bulkData
  )
  .get()

::: ::::