Elasticsearch Builder
This lib working with elasticsearch.js, flatten search params and query bodies.
Installation
npm install elastic-search-builder --save
Documentation
Usage
/* in ES 5 */const elasticsearch = ;const esb = ;/* in ES6 */;;/* new elasticsearch client */const client = host: 'localhost:9200';/* build search params by elastic-search-builder */const searchParams = body ;client
Bool Query
body ; // {// body: {// query: {// bool: {// must: [// {// "term" : { "user" : "kimchy" }// },// {// "term" : { "user" : "blob" }// }// ],// must_not: [// {// "term": { "user": "john" }// },// {// "term": { "user": "belly" }// }// ]// }// }// }// }
Aggregation
basic usage
body // {// "aggs": {// "all_name": {// "terms": {// "field": "name"// },// "aggs": {// "all_gender": {// "terms": {// "field": "gender"// },// "aggs": {// "all_city": {// "terms": {// "field": "city"// }// }// }// }// }// }// }// }
advanced usage
build nested aggragation without callback
body // {// "aggs": {// "by_gender": {// "terms": {// "field": "gender"// },// "aggs": {// "by_city": {// "terms": {// "field": "city"// },// "aggs": {// "all_name": {// "terms": {// "field": "name"// }// }// }// },// "by_language": {// "terms": {// "field": "language"// },// "aggs": {// "all_name": {// "terms": {// "field": "name"// }// }// }// }// }// }// }}
Development
debug with browser
npm run dev
run test
npm run test
build documentation
npm run build:docs
Manully publish to npm
npm loginnpm publish