Dart 2.x

Impport

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.

Arguments

Copied to clipboard!
Future<Map<String, dynamic>> import(
      String index, String collection, List<Map<String, dynamic>> documents)
Argument Type Description
index
String
Index name
collection
String
Collection name
documents
List<Map<String, dynamic>>
List of documents to import

documents

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:

Copied to clipboard!
[
  // 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, dynamic> containing 2 arrays:

Property Type Description
successes
List
Array of object containing successful document import
errors
List
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:

Property Type Description
_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:

Property Type Description
_id
String
Document unique identifier
status
int
HTTP status code for that query
error
Map<String, dynamic>
Error object

Each error object contain the following properties:

Property Type Description
type
String
Elasticsearch client error type
reason
String
human readable error message

Usage

Copied to clipboard!
final result = await kuzzle
  .bulk
  .import(
    'nyc-open-data',
    'yellow-taxi',
    [
      { 'index': { } },
      { 'a': 'document', 'with': 'any', 'number': 'of fields' },
      { 'create': { '_id': 'uniq-id-1' } },
      { 'another': 'document' },
      { 'create': { '_id': 'uniq-id-2' } },
      { 'and': { 'another': 'one' } },
    ]);