Skip to content

Commit

Permalink
Update docs for bulk helper
Browse files Browse the repository at this point in the history
Adds a section detailing how to modify documents before sending to the
bulk API, using the improvement introduced in
#1732
  • Loading branch information
JoshMock committed Jul 20, 2023
1 parent 6b4cdee commit 8b4d8a3
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion docs/helpers.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,33 @@ const result = await client.helpers.bulk({
console.log(result)
----

[discrete]
==== Modifying a document before operation

~Added~ ~in~ ~`v8.8.2`~

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.

[source,js]
----
const { Client } = require('@elastic/elasticsearch')
const client = new Client({
cloud: { id: '<cloud-id>' },
auth: { apiKey: 'base64EncodedKey' }
})
const result = await client.helpers.bulk({
datasource: [...]
onDocument (doc) {
return [
{ index: { _index: 'my-index' } },
{ ...doc, favorite_color: 'mauve' },
]
}
})
console.log(result)
----

[discrete]
[[multi-search-helper]]
Expand Down Expand Up @@ -574,4 +601,4 @@ const scrollSearch = client.helpers.scrollDocuments({
for await (const doc of scrollSearch) {
console.log(doc)
}
----
----

0 comments on commit 8b4d8a3

Please sign in to comment.