nestjs-opensearch
TypeScript icon, indicating that this package has built-in type declarations

0.3.2 • Public • Published

Nest Logo

nestjs-opensearch

OpenSearch module for NestJS framework
Installation · Usage · Issues
NPM Version Package License NPM Downloads


Installation

For NPM:

$ npm i --save nestjs-opensearch @opensearch-project/opensearch

For Yarn:

$ yarn add nestjs-opensearch @opensearch-project/opensearch

Usage

Module for single connection:

import { OpensearchModule } from 'nestjs-opensearch';

@Module({
  imports: [
    OpensearchModule.forRoot({
      node: 'https://*****.es.amazonaws.com',
    }),
  ],
  providers: (...),
})
export class SearchModule { }

Module for multiple connections:

import { OpensearchModule } from 'nestjs-opensearch';

@Module({
  imports: [
    OpensearchModule.forRoot({
      clientName: 'foo',
      node: 'https://*****.es.amazonaws.com',
    }),
    OpensearchModule.forRoot({
      clientName: 'bar',
      node: 'https://*****.es.amazonaws.com',
    }),
  ],
  providers: (...),
})
export class SearchModule { }

Module for async configuration:

import { OpensearchModule } from 'nestjs-opensearch';

@Module({
  imports: [
    // See also: https://docs.nestjs.com/techniques/configuration
    ConfigModule,
    OpensearchModule.forRootAsync({
      clientName: 'baz',
      inject: [ ConfigService ],
      useFactory: (configService) => ({
        node: configService.get<string>('opensearch.node'),
      }),
    }),
  ],
  providers: (...),
})
export class SearchModule { }

Client injection:

import { InjectOpensearchClient, OpensearchClient } from 'nestjs-opensearch';

@Injectable()
export class SearchService {
  public constructor(
    // Inject the default client
    private readonly searchClient: OpensearchClient,

    // Also inject the default client
    @InjectOpensearchClient()
    private readonly alsoSearchClient: OpensearchClient,

    // Inject the 'foo' named client
    @InjectOpensearchClient('foo')
    private readonly fooSearchClient: OpensearchClient,
  ) { }
}

Package Sidebar

Install

npm i nestjs-opensearch

Weekly Downloads

9,022

Version

0.3.2

License

MIT

Unpacked Size

16.4 kB

Total Files

21

Last publish

Collaborators

  • neoatlan