Skip to content

Instantly share code, notes, and snippets.

@paztek
Created July 20, 2020 07:36
Show Gist options
  • Save paztek/2a5838fd8f5b29eccf2264cc859fe642 to your computer and use it in GitHub Desktop.
Save paztek/2a5838fd8f5b29eccf2264cc859fe642 to your computer and use it in GitHub Desktop.
nestjs-elasticsearch-example-3
import { Module, OnModuleInit } from '@nestjs/common';
import { ElasticsearchModule as BaseElasticsearchModule, ElasticsearchService } from '@nestjs/elasticsearch';
import { v4 as uuid }from 'uuid';
@Module({
imports: [
BaseElasticsearchModule.register({
node: 'http://localhost:9200',
generateRequestId: () => uuid(),
}),
],
exports: [
BaseElasticsearchModule,
],
})
export class ElasticsearchModule implements OnModuleInit {
constructor(
private readonly client: ElasticsearchService,
) {}
public onModuleInit(): any {
this.client.on('request', (err, result) => {
const { id } = result.meta.request;
console.log('ES Request ID', id);
});
this.client.on('response', (err, result) => {
const { id } = result.meta.request;
console.log('ES Response ID', id);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment