[Backport 8.10] Throw an explicit error when asStream is used with bulk helper (#2080)
Co-authored-by: Josh Mock <joshua.mock@elastic.co>
This commit is contained in:
committed by
GitHub
parent
5fcc557a78
commit
745919c92d
@ -527,6 +527,8 @@ export default class Helpers {
|
|||||||
* @return {object} The possible operations to run with the datasource.
|
* @return {object} The possible operations to run with the datasource.
|
||||||
*/
|
*/
|
||||||
bulk<TDocument = unknown> (options: BulkHelperOptions<TDocument>, reqOptions: TransportRequestOptions = {}): BulkHelper<TDocument> {
|
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 client = this[kClient]
|
||||||
const { serializer } = client
|
const { serializer } = client
|
||||||
if (this[kMetaHeader] !== null) {
|
if (this[kMetaHeader] !== null) {
|
||||||
|
|||||||
@ -18,6 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import FakeTimers from '@sinonjs/fake-timers'
|
import FakeTimers from '@sinonjs/fake-timers'
|
||||||
|
import { AssertionError } from 'assert'
|
||||||
import { createReadStream } from 'fs'
|
import { createReadStream } from 'fs'
|
||||||
import * as http from 'http'
|
import * as http from 'http'
|
||||||
import { join } from 'path'
|
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()
|
t.end()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user