Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cch123/elastic-rs
comvert bool expression to elasticsearch DSL in rust
https://github.com/cch123/elastic-rs
boolean-expression dsl elastic elasticsearch rust sql
Last synced: about 1 month ago
JSON representation
comvert bool expression to elasticsearch DSL in rust
- Host: GitHub
- URL: https://github.com/cch123/elastic-rs
- Owner: cch123
- License: mit
- Created: 2019-01-20T17:40:39.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-07-21T00:54:29.000Z (over 1 year ago)
- Last Synced: 2024-05-03T01:24:20.820Z (6 months ago)
- Topics: boolean-expression, dsl, elastic, elasticsearch, rust, sql
- Language: Rust
- Homepage:
- Size: 36.1 KB
- Stars: 47
- Watchers: 3
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
- awesome-pest - elastic-rs - Convert bool expressions to Elasticsearch DSL in Rust. (Projects)
README
# Overview
Convert Bool Expression to Elasticsearch DSL.
```
+----------------------------------------------------+
|{ |
| "query": { |
| "bool": { |
| "must": [{ |
| "match": { |
| "a": { |
| "query": "1", |
| "type": "phrase" |
| } |
| } |
| }, { |
| "bool": { |
| "must": [{ |
| "match": { |
| "b": { |
+-----------------------------+ | "query": "2", |
|a = 1 and (b = 2 and (c = 3))|---------->| "type": "phrase" |
+-----------------------------+ | } |
| } |
| }, { |
| "match": { |
| "c": { |
| "query": "3", |
| "type": "phrase" |
| } |
| } |
| }] |
| } |
| }] |
| } |
| } |
|} |
+----------------------------------------------------+
```Example:
Add:
```toml
[dependencies]
elastic_query = "0.4.4"
```To your `Cargo.toml`, then use as follows:
```rust
extern crate elastic_query;fn main() {
let result = elastic_query::convert("a = 1 and b in (1,2,3)".to_string(), 0, 100, vec![], vec![]).unwrap();
println!("{}", result);
}```
Grammar:
```peg
bool_expr = { SOI ~ expr ~ EOI }expr = {
(paren_bool | comp_expr) ~ ( (and_op|or_op)~ (paren_bool| comp_expr))*
}and_op = { "and" }
or_op = { "or" }paren_bool = { "(" ~ expr ~ ")" }
comp_expr = { field ~ op ~ value }
field = @{ (ASCII_ALPHA ~ ASCII_ALPHANUMERIC*) }
op = { eq | neq | op_in | op_not_in | gt | gte | lt | lte | like | not_like }
eq = { "=" }
neq = { "!=" | "<>"}
op_in = { "in" }
op_not_in= { "not" ~ "in"}
gt = { ">" }
gte = { ">=" }
lt = { "<" }
lte = { "<=" }
like = { "like" }
not_like = { "not" ~ "like" }value = {
string_literal
| num_literal
| "(" ~ string_literal ~("," ~ string_literal)* ~ ")"
| "(" ~ num_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" }
```