ImportAsync #
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 #
public async Task<JObject> ImportAsync(
string index,
string collection,
JArray bulkData);
Argument | Type | Description |
---|---|---|
index | string | Index name |
collection | string | Collection name |
bulkData | JArray | 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 JObject containing 2 arrays:
Property | Type | Description |
---|---|---|
successes | JArray | Array of object containing successful document import |
errors | JArray | 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 | JObject | 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 #
try {
JArray bulkData = JArray.Parse(@"
[
{ index: { } },
{ a: 'document', with: 'any', number: 'of fields' },
{ create: { _id: 'uniq-id-1' } },
{ another: 'document' },
{ create: { _id: 'uniq-id-2' } },
{ and: { another: 'one' } }
]");
JObject response = await kuzzle.Bulk.ImportAsync(
"nyc-open-data",
"yellow-taxi",
bulkData);
Console.WriteLine(response.ToString(Formatting.None));
/*
{
errors: [],
successes: [
{
index: {
_id: "hQ10_GwBB2Y5786Pu_NO",
status: 201
}
},
{
create: {
_id: "uniq-id-1",
status: 201
}
},
{
create: {
_id: "uniq-id-2",
status: 201
}
}
]
}
*/
} catch (KuzzleException e) {
Console.WriteLine(e);
}