[Backport 8.11] Throw an explicit error when asStream is used with bulk helper (#2079)

Co-authored-by: Josh Mock <joshua.mock@elastic.co>
This commit is contained in:
github-actions[bot]
2023-11-16 10:44:50 -06:00
committed by GitHub
parent a6cae9f625
commit f9007d360f
2 changed files with 34 additions and 0 deletions

View File

@ -527,6 +527,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) {

View File

@ -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()
})