使用nestjs库@nestjs/elasticsearch,@elastic/elasticsearch
imports: [ConfigModule.forRoot( {
validationSchema,
validationOptions: {
abortEarly: true,
}
}),
SearchModule,
UserSkillsModule
],
controllers: [SearchController, UserSkillsController],
providers: [],
})
export class AppModule {}
search.module.ts搜索模块
@Module({
imports: [ConfigModule, ElasticsearchModule.registerAsync({
imports:[ConfigModule],
useFactory: async(configService: ConfigService) => ({
node: configService.get('ELASTICSEARCH_HOST')
}),
inject: [ConfigService],
}),],
providers: [SearchService],
exports: [SearchService, ElasticsearchModule]
})
export class SearchModule {}
.环境
ELASTICSEARCH_HOST= ((I have specified the url correctly))
搜索服务.ts
import { Injectable, InternalServerErrorException, Logger } from '@nestjs/common';
import { ElasticsearchService } from '@nestjs/elasticsearch';
import { UserSkills } from '../user-skills/dto/userSkill.interface';
@Injectable()
export class SearchService {
constructor(
private elasticsearchService: ElasticsearchService
){}
private logger = new Logger('SearchService');
async addUserSkills(userPublicId: string, companyPublicId: string, skills: UserSkills[]): Promise<any> {
const tempObj = {};
tempObj[userPublicId] = skills;
console.log('TEMP OBJECT ---- ', tempObj);
const document = {
index: companyPublicId,
body: tempObj
}
let result;
try {
result = await this.elasticsearchService.index(document);
} catch(error) {
this.logger.verbose(`Error creating an index ---- ${error}`);
throw new InternalServerErrorException(`Error creating index ---- ${error}`);
}
return result;
}
这将引发以下错误:
[Nest] 50872 - 09/17/2020, 9:29:21 AM [Error: Error creating index ---- ResponseError: index_not_found_exception]
我不确定我从文件中遗漏了什么。请帮帮我。谢谢您。
暂无答案!
目前还没有任何答案,快来回答吧!