@codemaskjs/nestjs-elasticsearch
v1.11.0
Published
Nestjs Elasticsearch Module
Downloads
16
Maintainers
Readme
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 @codemaskjs/nestjs-elasticsearch
// or
$ npm -i @codemaskjs/nestjs-elasticsearch
- Import module
import { ElasticsearchModule } from '@codemaskjs/nestjs-elasticsearch'
@Module({
imports: [
ElasticsearchModule.register({
node: 'http://localhost:9200'
})
]
})
class AppModule {}
- (optional) Registering Index with Document
import { RegisterIndex } from '@codemaskjs/nestjs-elasticsearch'
@RegisterIndex('examples')
export class ExampleDocument {
readonly id: string
readonly test?: string
}
import { Injectable } from '@nestjs/common'
import { Index } from '@codemaskjs/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 '@codemaskjs/nestjs-elasticsearch'
import { ExampleDocument } from './example.document'
@Module({
imports: [
providers: [ExampleService],
ElasticsearchModule.register({
node: 'http://localhost:9200'
}),
ElasticsearchModule.forFeature([
ExampleDocument
])
]
})
class AppModule {}
Future actions
- Add case_insensitive option to term search
- Filter undefined/null values from request body
- Add field to aggregations body so that it can return more than default 10 results
- Add and <search_after> fields to request type and field to response type to enable pagination
- Add
e2e
tests setup for features scenario tests - Add
extraction
of aggregations onresponse
- Add
healthcheck
fromElasticsearchService
- Add
checkDocumentIntegrity
with the connection on the source on runtime - Add optional
script
tosum
,avg
,max
aggregation - Add order field to
terms
aggregation