Build elasticsearch query with C-style boolean expression.
How to use
Use the expression to be parsed and a query factory to instanciate a queryBuilder (The queryBuilder will be instanciated only if the expression can be parsed without any problems)
The query factory is a 2-level map, which maps field-alias & comparator combinations to queryGenerator (a closure function). When queryGenerator is called, it will return a sub-query for the certain field with the given value.
Call the Build() function to finally build the query
Try it yourself
check ./query_builder_test.go
How it works
When an expression is given, it will:
Scan the expression and extract all tokens from it.
Use shunting-yard algorithm to convert these tokens to a suffix expression.
Parse the expression and return the final query
If the operator is a comparing operator and one of the operands is a field-alias, calls the queryGenerator to build a query.
If the operator is a logical operator and both of the operands are elastic.Query, use elastic.BoolQuery to group the sub queries.