To experiment with a Golang-based parser generator for translating string-based search queries of arbitrary complexity and nesting into JSON suitable for use with Elasticsearch.
Currently using github.com/pointlander/peg for parsing and gopkg.in/olivere/elastic.v5 for ES5-compatible query rendering.
The goal here is to play with the parser generator, not generate optimally-structured ES queries. The DSL can generate valid ES queries
that are not particularly performant or readable. Search results returned for a deeply nested query can be counterintuitive.
TODOs
Life is short and this tool has no practical use, but for fun it would be nice to also:
upgrade AST traversal business logic and grammar definitions to flatten/simplify generated queries
move value element parsing from the grammar into the traversal logic to provide more actionable error messages
support list-type values in queries, more query types etc.
add method for setting or defaulting various query params that have no clear place in such a DSL
Build & Run
Build the binary using make or make clean build
Binary will be compiled into dist/ dir, with generated parser generated to file grammar/dsl.peg.go
Try dist/es_dsl --help after running make, for detailed usage instructions
Example invocation: dist/es_dsl --verbose --filter --default 'message' --query 'DSL_QUERY_STRING'