Skip to content

Commit 9ee3a11

Browse files
authored
feat(helpers): Throw an explicit error when asStream is used with bulk helper (#37)
Porting elastic/elasticsearch-js@4269197
1 parent ad61cc3 commit 9ee3a11

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/helpers.ts

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

test/unit/helpers/bulk.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* under the License.
1818
*/
1919

20+
import { AssertionError } from 'assert'
2021
import * as http from 'http'
2122
import { createReadStream } from 'fs'
2223
import { join } from 'path'
@@ -1161,6 +1162,36 @@ test('transport options', t => {
11611162
})
11621163
})
11631164

1165+
t.test('Should not allow asStream request option', async t => {
1166+
t.plan(2)
1167+
1168+
const client = new Client({
1169+
node: 'http://localhost:9200',
1170+
})
1171+
1172+
try {
1173+
await client.helpers.bulk({
1174+
datasource: dataset.slice(),
1175+
flushBytes: 1,
1176+
concurrency: 1,
1177+
onDocument (doc) {
1178+
return { index: { _index: 'test' } }
1179+
},
1180+
onDrop (doc) {
1181+
t.fail('This should never be called')
1182+
},
1183+
}, {
1184+
headers: {
1185+
foo: 'bar'
1186+
},
1187+
asStream: true,
1188+
})
1189+
} catch (err: any) {
1190+
t.ok(err instanceof AssertionError)
1191+
t.equal(err.message, 'bulk helper: the asStream request option is not supported')
1192+
}
1193+
})
1194+
11641195
t.end()
11651196
})
11661197

0 commit comments

Comments
 (0)