Giter VIP home page Giter VIP logo

esqb's Introduction

esqb

Build elasticsearch query with C-style boolean expression.

How to use

see ./query_builder_test.go

The v1.0.0+ version is broken due to a bad commit :(, use v2 instead.

  1. import "github.com/r4ve1/esqb/v2"
  2. 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)
  3. 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.
  4. Call the Build() function to finally build the query

How it works

When an expression is given, it will:

  1. Scan the expression and extract all tokens from it.
  2. Use shunting-yard algorithm to convert these tokens to a suffix expression.
  3. 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.

Thanks to

  1. Lexer from govaluate
  2. Shunting-yard algorithm from go-shunting-yard

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.