Skip to content

Instantly share code, notes, and snippets.

@DmitriyIudokhin
Created July 24, 2023 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DmitriyIudokhin/7bff9837d05d7944f5c837923157b384 to your computer and use it in GitHub Desktop.
Save DmitriyIudokhin/7bff9837d05d7944f5c837923157b384 to your computer and use it in GitHub Desktop.
import { ElasticsearchService } from '@nestjs/elasticsearch';
export class IngredientService {
constructor(
...
private readonly elasticsearchService: ElasticsearchService
...
) {
public async elastic_search(pBody: any, pUser: UserDocument) {
let aQueryParams = {
index: process.env.ELASTIC_SEARCH_OPTICS_INDEX,
body: JSON.stringify(pBody),
};
let aResult = {};
try {
aResult = await this.elasticsearchService.search(aQueryParams);
} catch (e) {
this.logger.error(`ElasticSearchService search failed: ${e}`);
throw new HttpException(`${e}`, HttpStatus.INTERNAL_SERVER_ERROR);
}
return aResult;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment