elasticsearch索引未在nestjs中找到异常

rjjhvcjd  于 2021-06-14  发布在  ElasticSearch
关注(0)|答案(0)|浏览(342)

使用nestjs库@nestjs/elasticsearch,@elastic/elasticsearch

  1. imports: [ConfigModule.forRoot( {
  2. validationSchema,
  3. validationOptions: {
  4. abortEarly: true,
  5. }
  6. }),
  7. SearchModule,
  8. UserSkillsModule
  9. ],
  10. controllers: [SearchController, UserSkillsController],
  11. providers: [],
  12. })
  13. export class AppModule {}

search.module.ts搜索模块

  1. @Module({
  2. imports: [ConfigModule, ElasticsearchModule.registerAsync({
  3. imports:[ConfigModule],
  4. useFactory: async(configService: ConfigService) => ({
  5. node: configService.get('ELASTICSEARCH_HOST')
  6. }),
  7. inject: [ConfigService],
  8. }),],
  9. providers: [SearchService],
  10. exports: [SearchService, ElasticsearchModule]
  11. })
  12. export class SearchModule {}

.环境

  1. ELASTICSEARCH_HOST= ((I have specified the url correctly))

搜索服务.ts

  1. import { Injectable, InternalServerErrorException, Logger } from '@nestjs/common';
  2. import { ElasticsearchService } from '@nestjs/elasticsearch';
  3. import { UserSkills } from '../user-skills/dto/userSkill.interface';
  4. @Injectable()
  5. export class SearchService {
  6. constructor(
  7. private elasticsearchService: ElasticsearchService
  8. ){}
  9. private logger = new Logger('SearchService');
  10. async addUserSkills(userPublicId: string, companyPublicId: string, skills: UserSkills[]): Promise<any> {
  11. const tempObj = {};
  12. tempObj[userPublicId] = skills;
  13. console.log('TEMP OBJECT ---- ', tempObj);
  14. const document = {
  15. index: companyPublicId,
  16. body: tempObj
  17. }
  18. let result;
  19. try {
  20. result = await this.elasticsearchService.index(document);
  21. } catch(error) {
  22. this.logger.verbose(`Error creating an index ---- ${error}`);
  23. throw new InternalServerErrorException(`Error creating index ---- ${error}`);
  24. }
  25. return result;
  26. }

这将引发以下错误:

  1. [Nest] 50872 - 09/17/2020, 9:29:21 AM [Error: Error creating index ---- ResponseError: index_not_found_exception]

我不确定我从文件中遗漏了什么。请帮帮我。谢谢您。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题