Jashandeep Singh
1 min readDec 14, 2023

--

This works fine in my system using your mentioned module/library:

import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { OpensearchModule } from 'nestjs-opensearch';

@Module({
imports: [
OpensearchModule.forRoot({
node: 'https://localhost:9200',
auth: {
username: 'admin',
password: 'admin',
},
ssl: {
rejectUnauthorized: false,
},
}),
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}



import { Injectable } from '@nestjs/common';
import { InjectOpensearchClient, OpensearchClient } from 'nestjs-opensearch';

@Injectable()
export class AppService {

public constructor(
@InjectOpensearchClient()
private readonly searchClient: OpensearchClient,
) {}

async bulkDataIngestion(): Promise<any> {
try {
const dummyData = [
{ id: 1, name: 'Dummy 1' },
{ id: 2, name: 'Dummy 2' },
// Add more dummy data as needed
];

// Example: Indexing dummy data using the default search client
const bulkIndexResponse = await this.searchClient.bulk({
index: 'dummy',
body: dummyData.flatMap((doc) => [{ index: { _index: 'dummy' } }, doc]),
});

// Check the response or perform other operations based on the bulk indexing result
console.log('Bulk Index Response:', bulkIndexResponse);

// Return the response or perform additional operations
return bulkIndexResponse;
} catch (error) {
// Handle errors appropriately
console.error('Error during bulk data ingestion:', error);
throw error;
}
}
}

--

--

Jashandeep Singh
Jashandeep Singh

No responses yet