bodybuilder is a Node library that composes Elasticsearch query DSL JSON through a chainable API for queries, filters, aggregations, suggestions, sort, and pagination.
Overview
bodybuilder helps JavaScript applications construct Elasticsearch search request bodies without hand-writing nested JSON. You create a builder instance, add query, filter, aggregation, or suggestion clauses through predictable methods, then call build to obtain the object sent to Elasticsearch.
Queries attach to the bool structure the library maintains, and multiple filters combine using boolean must, should, and must_not semantics documented in Elasticsearch. Aggregations support nesting via callback functions so child metrics attach under parent buckets. Phrase and term suggesters, sort fields with optional advanced sort objects, from/size pagination, and arbitrary extra keys through rawOption are all supported.
The project aims to cover the full query DSL across Elasticsearch versions, with a v1 flag on build for 1.x-style output. A small REPL script ships for interactive experimentation. API documentation on Read the Docs lists method signatures and examples.
Key features
- Chainable query construction
- Bool filter combination helpers
- Nested aggregations
- Phrase and term suggesters
- Sort and pagination controls
- Raw extra request options
- Elasticsearch 1.x build mode
- Interactive REPL helper
Use cases
- Backend search endpoints
- Kibana-style custom searches
- Complex filtered aggregations
- Prototype queries in Node REPL
- Legacy Elasticsearch 1.x clients