diff --git a/src/helpers.ts b/src/helpers.ts index ceaed7524..525977193 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -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 (options: BulkHelperOptions, reqOptions: TransportRequestOptions = {}): BulkHelper { + bulk (options: BulkHelperOptions, reqOptions: TransportRequestOptions = {}): BulkHelper { 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, diff --git a/test/unit/helpers/bulk.test.ts b/test/unit/helpers/bulk.test.ts index d9bfcda6c..5a182009e 100644 --- a/test/unit/helpers/bulk.test.ts +++ b/test/unit/helpers/bulk.test.ts @@ -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({ 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' } }