Installations
npm install @nestjs/elasticsearch
Developer Guide
Typescript
Yes
Module System
N/A
Node Version
20.18.0
NPM Version
10.8.2
Score
87.4
Supply Chain
95.4
Quality
81.7
Maintenance
100
Vulnerability
99.3
License
Releases
Unable to fetch releases
validate.email 🚀
Verify real, reachable, and deliverable emails with instant MX records, SMTP checks, and disposable email detection.
Download Statistics
Total Downloads
8,524,299
Last Day
20,258
Last Week
97,037
Last Month
409,772
Last Year
3,143,498
Bundle Size
3.82 kB
Minified
1.09 kB
Minified + Gzipped
Package Meta Information
Latest Version
11.0.0
Package Id
@nestjs/elasticsearch@11.0.0
Unpacked Size
26.73 kB
Size
8.15 kB
File Count
27
NPM Version
10.8.2
Node Version
20.18.0
Published on
Jan 17, 2025
Oops! Something went wrong.
Peer Dependencies
3
A progressive Node.js framework for building efficient and scalable server-side applications.
Description
Elasticsearch module for Nest based on the official @elastic/elasticsearch package.
Installation
1$ npm i --save @nestjs/elasticsearch @elastic/elasticsearch
Usage
Import ElasticsearchModule
:
1@Module({ 2 imports: [ElasticsearchModule.register({ 3 node: 'http://localhost:9200', 4 })], 5 providers: [...], 6}) 7export class SearchModule {}
Inject ElasticsearchService
:
1@Injectable() 2export class SearchService { 3 constructor(private readonly elasticsearchService: ElasticsearchService) {} 4}
Async options
Quite often you might want to asynchronously pass your module options instead of passing them beforehand. In such case, use registerAsync()
method, that provides a couple of various ways to deal with async data.
1. Use factory
1ElasticsearchModule.registerAsync({ 2 useFactory: () => ({ 3 node: 'http://localhost:9200' 4 }) 5});
Obviously, our factory behaves like every other one (might be async
and is able to inject dependencies through inject
).
1ElasticsearchModule.registerAsync({ 2 imports: [ConfigModule], 3 useFactory: async (configService: ConfigService) => ({ 4 node: configService.get('ELASTICSEARCH_NODE'), 5 }), 6 inject: [ConfigService], 7}),
2. Use class
1ElasticsearchModule.registerAsync({ 2 useClass: ElasticsearchConfigService 3});
Above construction will instantiate ElasticsearchConfigService
inside ElasticsearchModule
and will leverage it to create options object.
1class ElasticsearchConfigService implements ElasticsearchOptionsFactory { 2 createElasticsearchOptions(): ElasticsearchModuleOptions { 3 return { 4 node: 'http://localhost:9200' 5 }; 6 } 7}
3. Use existing
1ElasticsearchModule.registerAsync({ 2 imports: [ConfigModule], 3 useExisting: ConfigService, 4}),
It works the same as useClass
with one critical difference - ElasticsearchModule
will lookup imported modules to reuse already created ConfigService
, instead of instantiating it on its own.
API Spec
The ElasticsearchService
wraps the Client
from the official @elastic/elasticsearch methods. The ElasticsearchModule.register()
takes options
object as an argument, read more.
Support
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.
Stay in touch
- Author - Kamil Myśliwiec
- Website - https://nestjs.com
- Twitter - @nestframework
License
Nest is MIT licensed.

No vulnerabilities found.

No security vulnerabilities found.
Other packages similar to @nestjs/elasticsearch
@codemask-labs/nestjs-elasticsearch
Schema based Elasticsearch, NestJS module with utilities, type-safe queries and aggregations builders.
@codemaskjs/nestjs-elasticsearch
Nestjs Elasticsearch Module
nestjs-opensearch
OpenSearch module for NestJS framework
nestjs-logger-elasticsearch
NestJS logging module for elasticsearch.