Propagate bulk helper document generic (#1606)
This commit is contained in:
committed by
GitHub
parent
194614564a
commit
dbfc8fc4d1
@ -520,7 +520,7 @@ export default class Helpers {
|
||||
* @param {object} reqOptions - The client optional configuration for this request.
|
||||
* @return {object} The possible operations to run with the datasource.
|
||||
*/
|
||||
bulk<TDocument = unknown> (options: BulkHelperOptions, reqOptions: TransportRequestOptions = {}): BulkHelper<TDocument> {
|
||||
bulk<TDocument = unknown> (options: BulkHelperOptions<TDocument>, reqOptions: TransportRequestOptions = {}): BulkHelper<TDocument> {
|
||||
const client = this[kClient]
|
||||
const { serializer } = client
|
||||
if (this[kMetaHeader] !== null) {
|
||||
@ -790,6 +790,7 @@ export default class Helpers {
|
||||
status: 429,
|
||||
error: null,
|
||||
operation: serializer.deserialize(bulkBody[i]),
|
||||
// @ts-expect-error
|
||||
document: operation !== 'delete'
|
||||
? serializer.deserialize(bulkBody[i + 1])
|
||||
/* istanbul ignore next */
|
||||
@ -841,6 +842,7 @@ export default class Helpers {
|
||||
status: responseItem.status,
|
||||
error: responseItem.error ?? null,
|
||||
operation: serializer.deserialize(bulkBody[indexSlice]),
|
||||
// @ts-expect-error
|
||||
document: operation !== 'delete'
|
||||
? serializer.deserialize(bulkBody[indexSlice + 1])
|
||||
: null,
|
||||
|
||||
@ -42,6 +42,11 @@ const dataset = [
|
||||
{ user: 'tyrion', age: 39 }
|
||||
]
|
||||
|
||||
interface Document {
|
||||
user: string
|
||||
age: number
|
||||
}
|
||||
|
||||
test('bulk index', t => {
|
||||
t.test('datasource as array', t => {
|
||||
t.test('Should perform a bulk request', async t => {
|
||||
@ -65,11 +70,12 @@ test('bulk index', t => {
|
||||
node: 'http://localhost:9200',
|
||||
Connection: MockConnection
|
||||
})
|
||||
const result = await client.helpers.bulk({
|
||||
const result = await client.helpers.bulk<Document>({
|
||||
datasource: dataset.slice(),
|
||||
flushBytes: 1,
|
||||
concurrency: 1,
|
||||
onDocument (doc) {
|
||||
t.type(doc.user, 'string') // testing that doc is type of Document
|
||||
return {
|
||||
index: { _index: 'test' }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user