Relastic
Simple Elasticsearch query builder
Installation
$ npm install relastic
Usage
Relastic uses method chaining to construct Elasticsearch queries.
var Relastic = require('relastic')
var r = new Relastic()
r.query().match({title: 'thai chili'})
r.output()
This approach can be much simpler than constructing large ES queries when compared to explicitly defining and modifying complex objects.
r.filter()
.bool()
.must()
.term({type: 'chili pepper'})
.terms({spiciness: ['high', 'very high']})
.should()
.term({color: 'green'})
.term({size: 'small'})
r.output()
Relastic also allows construction of query objects progressively.
r.filteredQuery()
.query()
.match({ingredients: 'cayenne'})
r.filteredQuery()
.filter()
.term({type: 'soup'})
r.output()
Each invocation of a Relastic query constructor method returns a chainable instance of Relastic. The chain can be started anew at whatever point the final method invocation referred to.
var bool = r.filter().bool()
bool.must().term({color: 'green'})
bool.must_not().terms({spiciness: ['none', 'low', 'medium']})
r.output()