Skip to content

Commit 8b4d8a3

Browse files
committed
Update docs for bulk helper
Adds a section detailing how to modify documents before sending to the bulk API, using the improvement introduced in #1732
1 parent 6b4cdee commit 8b4d8a3

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

docs/helpers.asciidoc

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,33 @@ const result = await client.helpers.bulk({
326326
console.log(result)
327327
----
328328

329+
[discrete]
330+
==== Modifying a document before operation
331+
332+
~Added~ ~in~ ~`v8.8.2`~
333+
334+
If you need to modify documents in your datasource before it is sent to Elasticsearch, you can return an array in the `onDocument` function rather than an operation object. The first item in the array must be the operation object, and the second item must be the document or partial document object as you'd like it to be sent to Elasticsearch.
335+
336+
[source,js]
337+
----
338+
const { Client } = require('@elastic/elasticsearch')
339+
340+
const client = new Client({
341+
cloud: { id: '<cloud-id>' },
342+
auth: { apiKey: 'base64EncodedKey' }
343+
})
344+
const result = await client.helpers.bulk({
345+
datasource: [...]
346+
onDocument (doc) {
347+
return [
348+
{ index: { _index: 'my-index' } },
349+
{ ...doc, favorite_color: 'mauve' },
350+
]
351+
}
352+
})
353+
354+
console.log(result)
355+
----
329356

330357
[discrete]
331358
[[multi-search-helper]]
@@ -574,4 +601,4 @@ const scrollSearch = client.helpers.scrollDocuments({
574601
for await (const doc of scrollSearch) {
575602
console.log(doc)
576603
}
577-
----
604+
----

0 commit comments

Comments
 (0)