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 :

add

elastic_query = "0.4.0"

to your Cargo.toml.

then:

```rust extern crate elastic_query;

fn main() { let result = elasticquery::convert("a = 1 and b in (1,2,3)".tostring(), 0, 100, vec![], vec![]).unwrap(); println!("{}", result); }

```

grammar :

```peg bool_expr = { SOI ~ expr ~ EOI }

expr = { andexpr | orexpr | parenbool | compexpr }

andexpr = { (parenbool | comp_expr) ~ "and" ~ (expr) }

orexpr = { (parenbool | comp_expr) ~ "or" ~ (expr) }

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

comp_expr = { field ~ op ~ value }

field = @{ (ASCIIALPHA ~ ASCIIALPHANUMERIC*) } op = { eq | neq | opin | opnotin | gt | gte | lt | lte | like | notlike } eq = { "=" } neq = { "!=" | "<>"} opin = { "in" } opnotin= { "not" ~ "in"} gt = { ">" } gte = { ">=" } lt = { "<" } lte = { "<=" } like = { "like" } notlike = { "not" ~ "like" }

value = { stringliteral | numliteral | "(" ~ stringliteral ~("," ~ stringliteral)* ~ ")" | "(" ~ numliteral ~("," ~ numliteral)* ~ ")" }

numliteral = @{ "-"? ~ ("0" | ASCIINONZERODIGIT ~ ASCIIDIGIT) ~ ("." ~ ASCII_DIGIT)? ~ (^"e" ~ ("+" | "-")? ~ ASCII_DIGIT+)? }

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

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

```