New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

@codemask-labs/nestjs-elasticsearch

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@codemask-labs/nestjs-elasticsearch

Schema based Elasticsearch, NestJS module with utilities, type-safe queries and aggregations builders.

77

Supply Chain Security

96

Quality

96

Maintenance

100

Vulnerabilities

100

License


Version published
Weekly downloads
213
decreased by-40%
Maintainers
5
Weekly downloads
 
Created
Issues
4

Nestjs Elasticsearch Module

[!NOTE]
This repository is a Work In Progress, driven by the motive.

Motive

Due to Production Experience when working with Elasticsearch leaded to maintenance issues when extensively used searches, filters and aggregations (especially aggregations).

  1. Current Elasticsearch Nestjs Modules does not provide auto-complete for queries
  2. Since Elasticsearch indexes are schema-less we got no proper feedback about what we should expect on the index
  3. Elasticsearch response forgets about types of aggregations

Adding package to your Nestjs project

  1. Install package using yarn or npm
$ yarn add @codemask-labs/nestjs-elasticsearch
// or
$ npm -i @codemask-labs/nestjs-elasticsearch
  1. Import module
import { ElasticsearchModule } from '@codemask-labs/nestjs-elasticsearch'

@Module({
    imports: [
        ElasticsearchModule.register({
            node: 'http://localhost:9200'
        })
    ]
})
class AppModule {}
  1. (optional) Registering Index with Document
import { RegisterIndex } from '@codemask-labs/nestjs-elasticsearch'

@RegisterIndex('examples')
export class ExampleDocument {
    readonly id: string
    readonly test?: string
}
import { Injectable } from '@nestjs/common'
import { Index } from '@codemask-labs/nestjs-elasticsearch'
import { ExampleDocument } from './example.document'

@Injectable()
export class ExampleService {
    @InjectIndex(ExampleDocument)
    private readonly exampleIndex: Index<ExampleDocument>

    getExampleDocuments() {
        return this.exampleIndex.search()
    }
}
import { ElasticsearchModule } from '@codemask-labs/nestjs-elasticsearch'
import { ExampleDocument } from './example.document'

@Module({
    imports: [
        providers: [ExampleService],
        ElasticsearchModule.register({
            node: 'http://localhost:9200'
        }),
        ElasticsearchModule.forFeature([
            ExampleDocument
        ])
    ]
})
class AppModule {}

Future actions

  1. Filter undefined/null values from request body
  2. Add checkDocumentIntegrity to check if documents are a valid based on an index schema
  3. Add optional script to sum, avg, max aggregation

FAQs

Package last updated on 24 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts