Skip to content

comvert bool expression to elasticsearch DSL in rust

License

Notifications You must be signed in to change notification settings

cch123/elastic-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview

Convert Bool Expression to Elasticsearch DSL.

                                                    ┌─────────────────────────────────────────────┐
                                                    │{                                            │
                                                    │    "bool": {                                │
                                                    │        "should": [{                         │
                                                    │            "match": {                       │
                                                    │                "a": {                       │
                                                    │                    "query": "1",            │
                                                    │                    "type": "phrase"         │
                                                    │                }                            │
                                                    │            }                                │
                                                    │        }, {                                 │
                                                    │            "bool": {                        │
                                                    │                "must": [{                   │
                                                    │                    "match": {               │
                                                    │                        "b": {               │
┌─────────────────────────────┐                     │                            "query": "2",    │
│ a = 1 or (b = 2 and c = 3)  │────────────────────▶│                            "type": "phrase" │
└─────────────────────────────┘                     │                        }                    │
                                                    │                    }                        │
                                                    │                }, {                         │
                                                    │                    "match": {               │
                                                    │                        "c": {               │
                                                    │                            "query": "3",    │
                                                    │                            "type": "phrase" │
                                                    │                        }                    │
                                                    │                    }                        │
                                                    │                }]                           │
                                                    │            }                                │
                                                    │        }]                                   │
                                                    │    }                                        │
                                                    │}                                            │
                                                    │                                             │
                                                    └─────────────────────────────────────────────┘

example :

fn main() {
    println!("hello world");
}

grammar :

bool_expr = { SOI ~ expr ~ EOI }

expr = {
    and_expr
    | or_expr
    | paren_bool
    | comp_expr
}

and_expr = {
    (paren_bool | comp_expr) ~ "and" ~ (expr)
}

or_expr = {
    (paren_bool | comp_expr)  ~ "or" ~ (expr)
}

paren_bool = { "(" ~ (expr) ~  ")" }

comp_expr = { field ~ op ~ value }

field = @{ (ASCII_ALPHA ~ ASCII_ALPHANUMERIC*) }
op = { "="| "!="| "<>"| "in" | "not in" | ">" | ">=" | "<" | "<=" | "like" }

value = { string_literal | num_literal }

num_literal = @{
    "-"?
    ~ ("0" | ASCII_NONZERO_DIGIT ~ ASCII_DIGIT*)
    ~ ("." ~ ASCII_DIGIT*)?
    ~ (^"e" ~ ("+" | "-")? ~ ASCII_DIGIT+)?
}

string_literal = ${ "\"" ~ string ~ "\"" }
string = @{ char* }
char = {
    !("\"" | "\\") ~ ANY
    | "\\" ~ ("\"" | "\\" | "/" | "b" | "f" | "n" | "r" | "t")
    | "\\" ~ ("u" ~ ASCII_HEX_DIGIT{4})
}

WHITESPACE = _{ " " | "\n" | "\r" }

About

comvert bool expression to elasticsearch DSL in rust

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages