Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@mobizerg/nest-elasticsearch
Advanced tools
Readme
A Elasticsearch integration module for Nest.js framework.
Yarn
yarn add @mobizerg/nest-elasticsearch @elastic/elasticsearch@7
NPM
npm install @mobizerg/nest-elasticsearch @elastic/elasticsearch@7 --save
Elasticsearch integration module for Nest.js based on the Elasticsearch package.
Import the ElasticsearchModule in app.module.ts
import { Module } from '@nestjs/common';
import { ElasticsearchModule } from '@mobizerg/nest-elasticsearch';
@Module({
imports: [
ElasticsearchModule.register(options)
],
})
export class AppModule {}
With Async
import { Module } from '@nestjs/common';
import { ElasticsearchModule } from '@mobizerg/nest-elasticsearch';
@Module({
imports: [
ElasticsearchModule.registerAsync({
imports: [ConfigModule],
useExisting: ElasticsearchConfigService,
}),
],
})
export class AppModule {}
Example config file (async)
import { Injectable } from '@nestjs/common';
import { ConfigService } from './config.service';
import { ElasticsearchModuleOptions, ElasticsearchOptionsFactory } from '@mobizerg/nest-elasticsearch';
@Injectable()
export class ElasticsearchConfigService implements ElasticsearchOptionsFactory {
constructor(private readonly config: ConfigService) {}
createElasticsearchOptions(name?: string): ElasticsearchModuleOptions {
return {
name,
node: 'http://localhost:9200',
maxRetries: 3,
requestTimeout: 60000,
};
}
}
Importing inside services
import { Injectable } from '@nestjs/common';
import { ElasticsearchService, InjectClient } from '@mobizerg/nest-elasticsearch';
import { Client } from '@elastic/elasticsearch';
@Injectable()
export class SearchService extends ElasticsearchService<T> {
constructor(@InjectClient()
readonly client: Client) {
super(client, {
index: 'tag',
settings: {
number_of_shards: 1,
number_of_replicas: 0,
refresh_interval: '2s',
analysis: {
analyzer: {
autocomplete: {
tokenizer: 'autocomplete',
filter: ['trim', 'lowercase'],
},
autocomplete_search: {
tokenizer: 'lowercase',
filter: ['trim'],
},
},
tokenizer: {
autocomplete: {
type: 'edge_ngram',
min_gram: 2,
max_gram: 12,
token_chars: ['letter', 'digit'],
},
},
},
},
properties: {
id: { type: 'integer' },
tag: { type: 'text', analyzer: 'autocomplete', search_analyzer: 'autocomplete_search' },
status: { type: 'byte' },
},
});
}
async find(query: string): Promise<any> {
try {
const { body } = await this.client.search({
index: this.config.index,
body: {
_source: ['id'],
from: 1,
size: 15,
query: {
bool: {
must: {
match: {
tag: {
query,
minimum_should_match: '80%',
},
},
},
},
},
},
});
return body;
} catch (error) {
return false;
}
}
}
MIT
FAQs
Elasticsearch integration module for nestjs framework
The npm package @mobizerg/nest-elasticsearch receives a total of 16 weekly downloads. As such, @mobizerg/nest-elasticsearch popularity was classified as not popular.
We found that @mobizerg/nest-elasticsearch demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.