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.
If some documents actions fail, the client will receive a PartialError error.
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 |
Return #
A JObject containing information about the import status for each document.
Property | Type | Description |
---|---|---|
errors | bool | Boolean indicating if some error occured during the import. |
items | JArray | Array containing the list of executed queries result, in the same order than in the query. |
Notes: Each object has the following properties:
Property | Type | Description |
---|---|---|
_id | string | Document unique identifier. |
status | int | HTTP status code for that query. 201 (created) or 206 (partial error). |
Usage #
try {
JArray bulkData = JArray.Parse(@"
[{ create: { _id: '1', _index: 'nyc-open-data', _type: 'yellow-taxi' } },
{ a: 'document', with: 'any', number: 'of fields' },
{ create: { _id: '2', _index: 'nyc-open-data', _type: 'yellow-taxi' } },
{ another: 'document' },
{ create: { _id: '3', _index: 'nyc-open-data', _type: 'yellow-taxi' } },
{ and: { another: 'one' } }]");
JObject response = await kuzzle.Bulk.ImportAsync("foo", "bar", bulkData);
Console.WriteLine(response.ToString(Formatting.None));
/*
{
"took": 49,
"errors": false,
"items": [
{
"create": {
"_index": "nyc-open-data",
"_type": "yellow-taxi",
"_id": "1",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"created": true,
"status": 201
}
},
{
"create": {
"_index": "nyc-open-data",
"_type": "yellow-taxi",
"_id": "2",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"created": true,
"status": 201
}
},
{
"create": {
"_index": "nyc-open-data",
"_type": "yellow-taxi",
"_id": "3",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"created": true,
"status": 201
}
}
]
}
*/
} catch (KuzzleException e) {
Console.WriteLine(e);
}
Edit this page on Github(opens new window)