diff --git a/src/helpers.ts b/src/helpers.ts index 768ad1dc8..0bd1b1c5c 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -527,6 +527,8 @@ export default class Helpers { * @return {object} The possible operations to run with the datasource. */ bulk (options: BulkHelperOptions, reqOptions: TransportRequestOptions = {}): BulkHelper { + assert(!(reqOptions.asStream ?? false), 'bulk helper: the asStream request option is not supported') + const client = this[kClient] const { serializer } = client if (this[kMetaHeader] !== null) { diff --git a/test/unit/helpers/bulk.test.ts b/test/unit/helpers/bulk.test.ts index 732d696c4..2c3229ce9 100644 --- a/test/unit/helpers/bulk.test.ts +++ b/test/unit/helpers/bulk.test.ts @@ -18,6 +18,7 @@ */ import FakeTimers from '@sinonjs/fake-timers' +import { AssertionError } from 'assert' import { createReadStream } from 'fs' import * as http from 'http' import { join } from 'path' @@ -1336,6 +1337,37 @@ 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') + }, + refreshOnCompletion: true + }, { + 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() })