A Object Document Mapping (ODM) manager for Elasticsearch written in TypeScript.
Can't wait to use it? Feel free to contribute.
- About
- Getting Started
- Features
- Prerequisites
- Installing
- License
- Contribute
- Tests
- Usage
- Built Using
- Authors
- Acknowledgments
Elastictype is a easy way to model application data stored in Elasticsearch. It is inspired by mongoose and @nestjs/mongoose and thus includes type casting, validation, query building, hooks and much more. It is written in TypeScript and provides type safety.
- Type casting
- Validation
- Query building
- Hooks
- Type safety
- Intuitive index declaration via Decorators
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
Please make sure you have installed the following tools:
- Node.js - JavaScript runtime environment
- Elasticsearch - Search engine
Install the package via npm:
npm install @cytex/elastictype --save
or via yarn:
yarn add @cytex/elastictype
import {
BaseSchema,
ElasticField,
ElasticDataType,
Index,
Model,
} from "@cytex/elastictype";
@Index({
name: "cats", // Name of the index
})
export class Cat extends BaseSchema<Cat> {
@Prop(ElasticDataType.Keyword)
public name: string;
@ElasticField({
// Type of the field (used for explicit mapping declaration)
type: ElasticDataType.Integer,
})
public age: number;
}
// Create the index and the mapping in Elasticsearch
Cat.syncMapping();
// Create a new cat
const cat = new Cat();
cat.name = "Garfield";
cat.age = 42;
// Save the cat to Elasticsearch
await cat.save();
// Update the cat
await cat.update({ age: 43 });
// Delete the cat
await cat.delete();
// Find all cats
const cats = await Cat.find({ age: 43 });
// Find a cat by id
const cat = await Cat.findById("foo");
Tests are written with jest. You can run them with the following command:
npm run test
In the vast realm of code, where ideas intertwine and innovation knows no bounds, I find myself continually amazed by the unwavering spirit of collaboration that defines the open source community. It's a world where developers, like you and me, share their creations, their insights, and their expertise with an unparalleled generosity. Countless times, whether through serendipitous discovery or through meticulous research, I've stumbled upon remarkable projects that have enriched my own journey as a developer.
Recognizing the profound impact that the open source community has had on my own growth, I've made a personal commitment to give back to this tapestry of ingenuity. The code is licensed under the Apache license, which means that you're free to use, remix, and build upon it. It's my way of extending the thread of collaboration that binds us as developers.
- TypeScript - Programming language
- Jest - Testing framework
- Elasticsearch JS - Elasticsearch client for Node.js
- Nestjs - Node.js framework
- @cytex-media-solutions - Project author
- @sjutz - Project maintainer [email protected]
- Nestjs - Node.js framework
- mongoose - MongoDB object modeling for Node.js
- @nestjs/mongoose - Mongoose module for Nest framework (not used in this project but inspired by it)