Elasticsearch Builder
![Coverage Status](https://coveralls.io/repos/github/weihanchen/elastic-search-builder/badge.svg)
This lib working with elasticsearch.js, flatten search params and query bodies.
Installation
npm install elastic-search-builder --save
Documentation
Usage
const elasticsearch = require('elasticsearch');
const esb = require('elastic-search-builder');
import elasticsearch from 'elasticsearch';
import esb from 'elastic-search-builder';
const client = new elasticsearch.Client({
host: 'localhost:9200'
});
const searchParams = esb()
.option()
.indices(['2016.01.01'])
.body()
.query({
match: {
dialogs: 'hello world'
}
}).build();
client.search(searchParams).then(body => {
console.log(body);
})
Bool Query
esb()
.body()
.query()
.bool()
.boolMust({
"term" : { "user" : "kimchy" }
}, {
"term" : { "user" : "blob" }
})
.boolNot([{
"term": { "user": "john" }
},{
"term": { "user": "belly" }
}])
.build();
Aggregation
basic usage
esb()
.body()
.aggs()
.appendAggs('all_name', 'terms', {
"field": "name"
})
.subAggs()
.appendAggs('all_gender', 'terms', {
"field": "gender"
})
.subAggs()
.appendAggs('all_city', 'terms', {
"field": "city"
})
.build()
advanced usage
build nested aggragation without callback
esb()
.body()
.aggs()
.appendAggs('by_gender', 'terms', {
"field": "gender"
})
.subAggs()
.forkAggs()
.appendAggs('by_city', 'terms', {
"field": "city"
})
.subAggs()
.appendAggs('all_name', 'terms', {
"field": "name"
})
.mergeAggs()
.appendAggs('by_language', 'terms', {
"field": "language"
})
.subAggs()
.appendAggs('all_name', 'terms', {
"field": "name"
})
.build()
}
Development
debug with browser
npm run dev
run test
npm run test
build documentation
npm run build:docs
Manully publish to npm
npm login
npm publish