ConfigurationError: Missing node(s) option using @nestjs/elasticsearch?
PeaceRebel opened this issue · comments
I'm submitting a...
[ ] Regression
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
ConfigurationError: Missing node(s) option
at new Client (<path_to_project>/node_modules/@elastic/elasticsearch/index.js:52:13)
at new ElasticsearchService (<path_to_project>/node_modules/@nestjs/elasticsearch/dist/elasticsearch.service.js:20:9)
at Injector.instantiateClass (<path_to_project>/node_modules/@nestjs/core/injector/injector.js:277:19)
at callback (<path_to_project>/node_modules/@nestjs/core/injector/injector.js:74:41)
at process._tickCallback (internal/process/next_tick.js:68:7)
at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
This is where the ElasticsearchModule
import { ElasticsearchService, ElasticsearchModule } from '@nestjs/elasticsearch';
import { ElasticSearchConfigService } from 'src/common/elasticsearchConfig.service';
@Module({
imports: [
.....
ElasticsearchModule.registerAsync({
useClass: ElasticSearchConfigService,
}),
],
})
export class SomeModule {}
And this is the ElasticSearchConfigService
:
import { Injectable } from '@nestjs/common';
import { ConfigService } from '../config/config.service';
import { ElasticsearchOptionsFactory, ElasticsearchModuleOptions } from '@nestjs/elasticsearch';
@Injectable()
export class ElasticSearchConfigService implements ElasticsearchOptionsFactory {
constructor(private readonly configService: ConfigService) {}
createElasticsearchOptions(): ElasticsearchModuleOptions {
return this.configService.get('elasticsearch');
}
}
The config service is passing the arguments correctly to the ElasticSearchConfigService, but I don't understand what happens after that. The client options are not reaching the Client constructor from @elastic/elasticsearch.
Environment
Nest version: 6.11.5
For Tooling issues:
- Node version: 10.15.2
- Platform: Linux (Debian buster)
Others:
ConfigurationError: Missing node(s) option
This error is thrown by Elasticsearch client.
It seems that this call:
Missing node(s) option
doesn't return the options object with the node
property defined.
Please, use our Discord channel (support) for such questions. We are using GitHub to track bugs, feature requests, and potential improvements.
I figured it out. I was specifying ElasticsearchService
as a provider in another module. That gets instantiated with a options
as null.
@PeaceRebel Can you explain how to fix this?
@apellizzn Please read my comment above. I don't really recall what exactly happened then. Better read the nestjs docs again.
I ended up using the basic elastic search client because there is not much documentation on how to use this wrapper
I'd agree on that last comment, it would be nice to have a bit more documentation (or even better, a sample project). Currently struggling with the exact same issue.
Please, check this comment #95 (comment). This error appears only if you pass a wrong options object as the elasticsearch configuration (missing properties).