![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@codemask-labs/nestjs-elasticsearch
Advanced tools
Schema based Elasticsearch, NestJS module with utilities, type-safe queries and aggregations builders.
Welcome to Nestjs Elasticsearch module based on @nestjs/elasticsearch package.
This package originates from our experience with using Elasticsearch in production environments, which leaded to maintenance issues when extensively used aggregations, searches and filters (especially aggregations).
The main issues we encountered and which our package fixes are:
Quick Setup: Get up and running in minutes using our easy-to-understand API.
Developer Experience: Designed with developers in mind, package prioritizes ease of use and efficiency throughout the development process.
Full TypeScript Support: Enjoy the benefits of code autocompletion and types for both request and response objects. Unlike the original Elasticsearch library, this package provides full type definitions in order to provide better development experience and minimize runtime errors.
Utility Methods: Say goodbye to repetitive boilerplate code. The package offers set of utility methods for most common Elasticsearch filtering, sorting, pagination and aggregations use cases.
Schema definitions: Elasticsearch index itself may be schema-less, but we integrated schema definitions into our package. Each schema maps to an Elasticsearch index. This gives us clear data model, which can be used when building request object, ensuring only fields available for given index are used. These definitions are also used to register indexes in module scope and inject them into a service, similar to how it is approached in TypeORM NestJS module.
You can install package using yarn or npm
$ yarn add @codemask-labs/nestjs-elasticsearch
// or
$ npm i @codemask-labs/nestjs-elasticsearch
Once the package is installed, you can start with importing the ElasticsearchModule
into the AppModule
.
import { ElasticsearchModule } from '@codemask-labs/nestjs-elasticsearch'
@Module({
imports: [
ElasticsearchModule.register({
node: 'http://localhost:9200'
})
]
})
class AppModule {}
The register()
method supports all the configuration properties available in ClientOptions
from the @elastic/elasticsearch package.
You can define index schema with @RegisterIndex()
decorator.
import { RegisterIndex } from '@codemask-labs/nestjs-elasticsearch'
@RegisterIndex('examples')
export class ExampleDocument {
readonly id: string
readonly exampleField: string
readonly exampleNumericField: number
}
The ElasticsearchModule
provides the forFeature()
method to configure the module and define which indexes should be registered in the current scope.
import { ElasticsearchModule } from '@codemask-labs/nestjs-elasticsearch'
import { ExampleDocument } from './example.document'
@Module({
imports: [ElasticsearchModule.forFeature([ExampleDocument])],
providers: [ExampleService]
})
export class ExampleModule {}
With module configuration in place, we can inject the ExampleDocument
into the ExampleService
using the @InjectIndex()
decorator:
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()
}
}
Now you can start creating request to Elasticsearch.
Once you finish the Getting Started guide, you can start building Elasticsearch request objects.
You can put request object directly in the search()
method
import { getBoolQuery, getTermQuery, Order } from '@codemask-labs/nestjs-elasticsearch'
getExampleDocuments() {
return this.exampleIndex.search({
size: 10,
query: getBoolQuery({
must: [
getTermQuery('exampleField.keyword', 'Some value'),
getRangeQuery('exampleNumericField', {
gte: 1,
lte: 10
})
]
}),
sort: {
'exampleField.keyword': {
order: Order.ASC
}
}
})
}
or use getSearchRequest()
method if you want to move request creation to some other place, but still laverage full type support and autocompletion.
import {
getBoolQuery,
getTermQuery,
getSearchRequest,
Order
} from '@codemask-labs/nestjs-elasticsearch'
import { ExampleDocument } from './example.document'
const searchRequestBody = getSearchRequest(ExampleDocument, {
size: 10,
query: getBoolQuery({
must: [
getTermQuery('exampleField.keyword', 'Some value'),
getRangeQuery('exampleNumericField', {
gte: 1,
lte: 10
})
]
}),
sort: {
'exampleField.keyword': {
order: Order.ASC
}
}
})
As for now the package provides utils for the following filter queries:
Use getBoolQuery()
for Boolean query
and its most common occurrence types:
getMustNotQuery()
for Must not querygetShouldQuery()
for Should querygetMustQuery()
for Must queryTogether with that you can also use getMinimumShouldMatchParameter()
for minimum_should_match parameter
getMatchPhrasePrefixQuery()
for Match phrase prefix querygetMatchQuery()
for Match querygetTermQuery()
for Term querygetTermsQuery()
for Terms querygetRangeQuery()
for Range querygetExistsQuery
for Exists queryAs for now the package provides utils for the following aggregation queries:
getCompositeAggregation()
for Composite aggregationgetDateHistogramAggregation()
for Date histogram aggregationgetMissingValueAggregation()
for Missing aggregationgetHistogramAggregation()
Histogram aggregationgetRangeAggregation()
for Range aggregationgetTermsAggregation()
for Terms aggregationgetAvgAggregation()
for Avg aggregationgetCardinalityAggregation()
for Cardinality aggregationgetMaxAggregation()
for Max aggregationgetMinAggregation()
for Min aggregationgetPercentileAggregation()
for Percentiles aggregationgetSumAggregation()
for Sum aggregationgetTopHitsAggregation()
for Top hits aggregationgetValueCountAggregation()
for Value count aggregationgetStatsBucketAggregation()
for Stats bucket aggregationMIT
FAQs
Schema based Elasticsearch, NestJS module with utilities, type-safe queries and aggregations builders.
We found that @codemask-labs/nestjs-elasticsearch demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.