Created
July 20, 2020 07:36
-
-
Save paztek/2a5838fd8f5b29eccf2264cc859fe642 to your computer and use it in GitHub Desktop.
nestjs-elasticsearch-example-3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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