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).
- Current Elasticsearch Nestjs Modules does not provide auto-complete for queries
- Since Elasticsearch indexes are schema-less we got no proper feedback about what we should expect on the index
- Elasticsearch response forgets about types of aggregations
Adding package to your Nestjs project
- Install package using yarn or npm
$ yarn add @codemask-labs/nestjs-elasticsearch
// or
$ npm -i @codemask-labs/nestjs-elasticsearch
- Import module
import { ElasticsearchModule } from '@codemask-labs/nestjs-elasticsearch'
@Module({
imports: [
ElasticsearchModule.register({
node: 'http://localhost:9200'
})
]
})
class AppModule {}
- (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
- Filter undefined/null values from request body
- Add
checkDocumentIntegrity
to check if documents are a valid based on an index schema - Add optional
script
to sum
, avg
, max
aggregation