https://github.com/jacobwgillespie/elastic-ts
TypeScript + Elasticsearch + magic ✨
https://github.com/jacobwgillespie/elastic-ts
elasticsearch query-builder typescript
Last synced: about 1 year ago
JSON representation
TypeScript + Elasticsearch + magic ✨
- Host: GitHub
- URL: https://github.com/jacobwgillespie/elastic-ts
- Owner: jacobwgillespie
- License: mit
- Created: 2018-04-23T20:46:31.000Z (about 8 years ago)
- Default Branch: main
- Last Pushed: 2024-09-26T08:15:44.000Z (almost 2 years ago)
- Last Synced: 2025-03-29T05:09:01.612Z (over 1 year ago)
- Topics: elasticsearch, query-builder, typescript
- Language: TypeScript
- Homepage:
- Size: 1.25 MB
- Stars: 41
- Watchers: 5
- Forks: 12
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# ✨ elastic-ts
[](https://travis-ci.org/jacobwgillespie/elastic-ts)

[](https://www.npmjs.com/package/elastic-ts)
[](https://www.npmjs.com/package/elastic-ts)

A TypeScript module for working with Elasticsearch.
### Goals
- Provide TypeScript types for Elasticsearch queries
- Provide a typed query body builder with an immutable API
### Non-goals
- Replace the official Elasticsearch API client
## Requirements
- TypeScript 2.8 - this project uses conditional types which were introduced in TypeScript 2.8
## Installation
```
yarn add elastic-ts
```
## Usage
### Types
```typescript
import {SearchBody} from 'elastic-ts'
const body: SearchBody = {
query: {
match_all: {},
},
}
```
### Builder
```typescript
import {esBuilder} from 'elastic-ts'
const body = esBuilder()
.query('match_all', {})
.filter('terms', 'field', ['one', 'two'])
.build()
```
### Credits
The query builder API is heavily inspired by [bodybuilder](https://github.com/danpaz/bodybuilder), although there are subtle API and behavioral differences.
### Contributing
You can build the project by running `yarn build`, or can be continuously built with `yarn watch`. Tests are executed by running `yarn test`.
**NOTE:** the tests run against the _built_ output files, so you will need to run `yarn build` or `yarn watch` before running `yarn test`.
### License
The MIT license. See `LICENSE`.