Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,8 @@ export default class Helpers {
* @return {object} The possible operations to run with the datasource.
*/
bulk<TDocument = unknown> (options: BulkHelperOptions<TDocument>, reqOptions: TransportRequestOptions = {}): BulkHelper<TDocument> {
assert(!(reqOptions.asStream ?? false), 'bulk helper: the asStream request option is not supported')

const client = this[kClient]
const { serializer } = client
if (this[kMetaHeader] !== null) {
Expand Down
31 changes: 31 additions & 0 deletions test/unit/helpers/bulk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/

import { AssertionError } from 'assert'
import * as http from 'http'
import { createReadStream } from 'fs'
import { join } from 'path'
Expand Down Expand Up @@ -1161,6 +1162,36 @@ test('transport options', t => {
})
})

t.test('Should not allow asStream request option', async t => {
t.plan(2)

const client = new Client({
node: 'http://localhost:9200',
})

try {
await client.helpers.bulk({
datasource: dataset.slice(),
flushBytes: 1,
concurrency: 1,
onDocument (doc) {
return { index: { _index: 'test' } }
},
onDrop (doc) {
t.fail('This should never be called')
},
}, {
headers: {
foo: 'bar'
},
asStream: true,
})
} catch (err: any) {
t.ok(err instanceof AssertionError)
t.equal(err.message, 'bulk helper: the asStream request option is not supported')
}
})

t.end()
})

Expand Down