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.
@gojob/ts-elasticsearch
Advanced tools
Changelog
[1.3.3] 2019-06-17
bulkSize
option to bulkIndex
methodReadme
To publish a new version of this package, you have to build the project before run npm publish
.
The purpose of this library is to provide a decorated class approch to use the elasticsearch module.
yarn add @gojob/ts-elasticsearch
import { Field, Elasticsearch, Primary } from '@gojob/ts-elasticsearch';
@Index()
class User {
@Primary()
@Field({ enabled: false})
id: string;
@Field('text') name: string;
@Field('integer') age: number;
}
// ...
const elasticsearch = new Elasticsearch({ host: 'http://192.168.99.100:9200' });
await elasticsearch.indices.create(User);
await elasticsearch.indices.putMapping(User);
const user = new User();
user.id = 'agent-1122';
user.name = 'Smith';
user.age = 33;
await elasticsearch.index(user);
await elasticsearch.indices.refresh(User);
const { documents } = elasticsearch.search(User, { body: { query: { match_all: {} } } });
@Index
Keep in mind that index types are scheduled to be removed in Elasticsearch 8.
This class decorator factory declares a new Elasticsearch index.
By default, it uses the class name as index (and type), but it can be overwritten.
Index settings may be added in the settings
optional parameter.
@Index({index: 'twt', settings: { number_of_shards: 3 } })
class Tweeter {}
@Primary
This property decorator factory declares the class primary key which will be used as _id
in Elasticsearch index.
When not provided, Elasticsearch generates ids by it own.
@Index()
class User {
@Primary()
@Field({ enabled: false})
id: string;
@Field('text') name: string;
@Field('integer') age: number;
}
@Field
This property decorator factory declares a new property in the current class.
It takes either a simple type as string or an elasticsearch mapping setting.
@Index()
class User {
@Field('keyword') id: string;
@Field({ type: 'text', boost: 2 })name: string;
@Field('integer') age: number;
}
When dealing with object or nested, you have to declare a class with some fields declared.
Notice in this case, the class in not decorated with @Index
.
Object example:
class Country {
@Field('text') name: string;
}
@Index()
class City {
@Field('text') name: string;
@Field({ object: Country })
country: Country;
}
Nested example:
class Follower {
@Field({ enabled: false}) name: string;
@Field({ enabled: false}) popularity: number;
}
@Index()
class User {
@Primary()
@Field({ enabled: false})
id: string;
@Field('text') name: string;
@Field({ nested: Follower })
followers: Follower[];
}
This class provides main elasticsearch features directly usable with indexed classes.
The purpose of this library is not to override all official plugin features, but only those that are relevant for managing documents using classes.
When dealing with documents, you can either uses indexed class instances or literal object associated to their indexed class.
The examples presents in this chapter are based on this setup.
import { Field, Elasticsearch, Primary } from '@gojob/ts-elasticsearch';
const elasticsearch = new Elasticsearch({ host: 'http://192.168.99.100:9200' });
@Index()
class User {
@Primary()
@Field({ enabled: false})
id: string;
@Field('text') name: string;
@Field('integer') age: number;
}
Instanciate this class with an IConfigOptions or an official elasticsearch.Client instance.
IConfigOptions extends the official client configuration option.
Extended options provided by IConfigOptions:
Name | Type | Optional | Description |
---|---|---|---|
client | elasticsearch.Client | X | Official client instance to use |
indexPrefix | string | X | Prefix to set to all indices |
The main class provides the main part of the document API functions.
The indices provides the main part of the document API functions.
FAQs
Elasticsearch decorated by TypeScript
The npm package @gojob/ts-elasticsearch receives a total of 7 weekly downloads. As such, @gojob/ts-elasticsearch popularity was classified as not popular.
We found that @gojob/ts-elasticsearch demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 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
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.