• Stars
    star
    382
  • Rank 112,241 (Top 3 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 6 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Elasticsearch module based on the official elasticsearch package ๐ŸŒฟ

Nest Logo

A progressive Node.js framework for building efficient and scalable server-side applications.

NPM Version Package License NPM Downloads Coverage Discord Backers on Open Collective Sponsors on Open Collective

Description

Elasticsearch module for Nest based on the official @elastic/elasticsearch package.

Installation

$ npm i --save @nestjs/elasticsearch @elastic/elasticsearch

Usage

Import ElasticsearchModule:

@Module({
  imports: [ElasticsearchModule.register({
    node: 'http://localhost:9200',
  })],
  providers: [...],
})
export class SearchModule {}

Inject ElasticsearchService:

@Injectable()
export class SearchService {
  constructor(private readonly elasticsearchService: ElasticsearchService) {}
}

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

ElasticsearchModule.registerAsync({
  useFactory: () => ({
    node: 'http://localhost:9200'
  })
});

Obviously, our factory behaves like every other one (might be async and is able to inject dependencies through inject).

ElasticsearchModule.registerAsync({
  imports: [ConfigModule],
  useFactory: async (configService: ConfigService) => ({
    node: configService.get('ELASTICSEARCH_NODE'),
  }),
  inject: [ConfigService],
}),

2. Use class

ElasticsearchModule.registerAsync({
  useClass: ElasticsearchConfigService
});

Above construction will instantiate ElasticsearchConfigService inside ElasticsearchModule and will leverage it to create options object.

class ElasticsearchConfigService implements ElasticsearchOptionsFactory {
  createElasticsearchOptions(): ElasticsearchModuleOptions {
    return {
      node: 'http://localhost:9200'
    };
  }
}

3. Use existing

ElasticsearchModule.registerAsync({
  imports: [ConfigModule],
  useExisting: ConfigService,
}),

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

License

Nest is MIT licensed.

More Repositories

1

nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript ๐Ÿš€
TypeScript
67,297
star
2

awesome-nestjs

A curated list of awesome things related to NestJS ๐Ÿ˜Ž
10,616
star
3

nest-cli

CLI tool for Nest applications ๐Ÿน
TypeScript
1,939
star
4

typeorm

TypeORM module for Nest framework (node.js) ๐Ÿ‡
TypeScript
1,906
star
5

typescript-starter

Nest framework TypeScript starter โ˜•
TypeScript
1,854
star
6

swagger

OpenAPI (Swagger) module for Nest framework (node.js) ๐ŸŒŽ
TypeScript
1,671
star
7

graphql

GraphQL (TypeScript) module for Nest framework (node.js) ๐Ÿท
TypeScript
1,453
star
8

docs.nestjs.com

The official documentation https://docs.nestjs.com ๐Ÿ“•
TypeScript
1,190
star
9

cqrs

A lightweight CQRS module for Nest framework (node.js) ๐ŸŽˆ
TypeScript
827
star
10

terminus

Terminus module for Nest framework (node.js) ๐Ÿค–
TypeScript
668
star
11

throttler

A rate limiting module for NestJS to work with Fastify, Express, GQL, Websockets, and RPC ๐Ÿงญ
TypeScript
619
star
12

bull

Bull module for Nest framework (node.js) ๐Ÿฎ
TypeScript
602
star
13

jwt

JWT utilities module based on the jsonwebtoken package ๐Ÿ”“
TypeScript
599
star
14

mongoose

Mongoose module for Nest framework (node.js) ๐Ÿธ
TypeScript
520
star
15

config

Configuration module for Nest framework (node.js) ๐Ÿ“
TypeScript
513
star
16

passport

Passport module for Nest framework (node.js) ๐Ÿ”‘
TypeScript
497
star
17

serve-static

Serve static websites (SPA's) using Nest framework (node.js) ๐Ÿฅฆ
TypeScript
454
star
18

ng-universal

Angular Universal module for Nest framework (node.js) ๐ŸŒท
TypeScript
441
star
19

schematics

Nest architecture element generation based on Angular schematics ๐ŸŽฌ
TypeScript
382
star
20

mapped-types

Configuration module for Nest framework (node.js) ๐Ÿบ
TypeScript
374
star
21

schedule

Schedule module for Nest framework (node.js) โฐ
TypeScript
350
star
22

sequelize

Sequelize module for Nest framework (node.js) ๐Ÿˆ
TypeScript
231
star
23

axios

Axios module for Nest framework (node.js) ๐Ÿ—‚
TypeScript
219
star
24

event-emitter

Event Emitter module for Nest framework (node.js) ๐Ÿฆ‹
TypeScript
193
star
25

serverless-core-deprecated

[Deprecated] Serverless Core module for Nest framework (node.js) ๐ŸฆŠ
TypeScript
171
star
26

azure-func-http

Azure Functions HTTP adapter for Nest framework (node.js) ๐ŸŒฅ
TypeScript
151
star
27

nestjs.com

The official website https://nestjs.com ๐Ÿ†
HTML
135
star
28

courses.nestjs.com

Official NestJS Courses website https://courses.nestjs.com ๐Ÿก
HTML
126
star
29

cache-manager

Cache manager module for Nest framework (node.js) ๐Ÿ—ƒ
TypeScript
118
star
30

javascript-starter

Nest framework JavaScript (ES6, ES7, ES8) + Babel starter ๐Ÿฐ
JavaScript
117
star
31

azure-database

Azure CosmosDB Database module for Nest framework (node.js) โ˜๏ธ
TypeScript
105
star
32

azure-storage

Azure Storage module for Nest framework (node.js) โ˜๏ธ
TypeScript
86
star
33

enterprise.nestjs.com

The official website https://enterprise.nestjs.com ๐ŸŒ
HTML
18
star
34

newsletter.nestjs.com

Official NestJS Newsletter website https://newsletter.nestjs.com ๐Ÿ“ฉ
HTML
12
star