Skip to content

Commit f9007d3

Browse files
[Backport 8.11] Throw an explicit error when asStream is used with bulk helper (#2079)
Co-authored-by: Josh Mock <[email protected]>
1 parent a6cae9f commit f9007d3

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/helpers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,8 @@ export default class Helpers {
527527
* @return {object} The possible operations to run with the datasource.
528528
*/
529529
bulk<TDocument = unknown> (options: BulkHelperOptions<TDocument>, reqOptions: TransportRequestOptions = {}): BulkHelper<TDocument> {
530+
assert(!(reqOptions.asStream ?? false), 'bulk helper: the asStream request option is not supported')
531+
530532
const client = this[kClient]
531533
const { serializer } = client
532534
if (this[kMetaHeader] !== null) {

test/unit/helpers/bulk.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919

2020
import FakeTimers from '@sinonjs/fake-timers'
21+
import { AssertionError } from 'assert'
2122
import { createReadStream } from 'fs'
2223
import * as http from 'http'
2324
import { join } from 'path'
@@ -1336,6 +1337,37 @@ test('transport options', t => {
13361337
})
13371338
})
13381339

1340+
t.test('Should not allow asStream request option', async t => {
1341+
t.plan(2)
1342+
1343+
const client = new Client({
1344+
node: 'http://localhost:9200',
1345+
})
1346+
1347+
try {
1348+
await client.helpers.bulk({
1349+
datasource: dataset.slice(),
1350+
flushBytes: 1,
1351+
concurrency: 1,
1352+
onDocument (doc) {
1353+
return { index: { _index: 'test' } }
1354+
},
1355+
onDrop (doc) {
1356+
t.fail('This should never be called')
1357+
},
1358+
refreshOnCompletion: true
1359+
}, {
1360+
headers: {
1361+
foo: 'bar'
1362+
},
1363+
asStream: true,
1364+
})
1365+
} catch (err: any) {
1366+
t.ok(err instanceof AssertionError)
1367+
t.equal(err.message, 'bulk helper: the asStream request option is not supported')
1368+
}
1369+
})
1370+
13391371
t.end()
13401372
})
13411373

0 commit comments

Comments
 (0)