onSuccess function for bulk helper (#2199)

* Bulk helper onSuccess callback

For https://github.com/elastic/elasticsearch-js/issues/2090

Includes refactor of the tryBulk result processing code, to make
iterating over bulk response data easier to understand.

* Add onSuccess tests for each datasource type

* Cleanup, additional comments

* Add documentation for onSuccess callback

* Update changelog

* Drop link to 8.14 release notes.

Page not yet published, breaking docs build.
This commit is contained in:
Josh Mock
2024-04-02 14:38:09 -05:00
committed by GitHub
parent e2974b0747
commit 4aa00e03e1
4 changed files with 429 additions and 173 deletions

View File

@ -1,6 +1,14 @@
[[changelog-client]]
== Release notes
[discrete]
=== 8.14.0
[discrete]
===== `onSuccess` callback added to bulk helper
The bulk helper now supports an `onSuccess` callback that will be called for each successful operation. https://github.com/elastic/elasticsearch-js/pull/2199[#2199]
[discrete]
=== 8.13.0

View File

@ -98,6 +98,17 @@ const b = client.helpers.bulk({
})
----
|`onSuccess`
a|A function that is called for each successful operation in the bulk request, which includes the result from Elasticsearch along with the original document that was sent, or `null` for delete operations.
[source,js]
----
const b = client.helpers.bulk({
onSuccess ({ result, document }) {
console.log(`SUCCESS: Document ${result.index._id} indexed to ${result.index._index}`)
}
})
----
|`flushBytes`
a|The size of the bulk body in bytes to reach before to send it. Default of 5MB. +
_Default:_ `5000000`