Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/allo-media/elm-es-simple-query-string
Parse and serialize ElasticSearch query strings.
https://github.com/allo-media/elm-es-simple-query-string
elasticsearch elm parser query
Last synced: about 2 months ago
JSON representation
Parse and serialize ElasticSearch query strings.
- Host: GitHub
- URL: https://github.com/allo-media/elm-es-simple-query-string
- Owner: allo-media
- License: mit
- Created: 2019-06-24T22:34:27.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-12-09T13:48:12.000Z (about 5 years ago)
- Last Synced: 2023-08-08T20:37:49.226Z (over 1 year ago)
- Topics: elasticsearch, elm, parser, query
- Language: Elm
- Homepage: https://package.elm-lang.org/packages/allo-media/elm-es-simple-query-string/latest/
- Size: 66.4 KB
- Stars: 1
- Watchers: 7
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Elm simple elastic query
Parse and serialize [ElasticSearch](https://www.elastic.co/en) search query strings.
This package allows to parse an
[elastic simple query string](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-simple-query-string-query.html#_simple_query_string_syntax)
into an [AST](https://en.wikipedia.org/wiki/Abstract_syntax_tree), and serialize
string search queries out of it.**Notes:**
- Serialization will enforce classic boolean operator precedence by using
parenthesis groups everywhere applicable.[Demo](https://allo-media.github.io/elm-es-simple-query-string/)
## Alphabet
( ) Group
[WORD] Char+
| OR
\+ AND
-- Exclude
"" Exact
~n Fuzzy
\* PrefixSpecific case : Spaces (signifying in some contexts and not in others)
## AST
```elm
type Expr
= And (List Expr)
| Exact String
| Exclude Expr
| Fuzzy Int String
| Or (List Expr)
| Prefix String
| Word String
```## Production rules
Unless explicitly indicated, spaces are ignored.
Query => ORExpr EOF
ORExpr => ANDExpr | ANDExpr "|" ORExpr
ANDExpr => EXCExpr | EXCExpr ("+"|\s+) ANDExpr
EXCExpr => "-" GRPExpr | GRPExpr
GRPExpr => WORD~"\*" | WORD~"\~2" | WORD | \" EXACTExpr \" | "(" ORExpr ")"
EXACTExpr => [^"]+## Example
Source query string:
big* (potatoes | "french fries") -salad
Parsing:
$ elm repl
---- Elm 0.19.0 ----------------------------------------------------------------
Read to learn more: exit, help, imports, etc.
--------------------------------------------------------------------------------
> import Elastic exposing (Expr(..))
> Elastic.parse "big* (potatoes | \"french fries\") -salad"
Ok (And [Prefix "big",Or [Word "potatoes",Exact ("french fries")],Exclude (Word "salad")])
: Result (List Parser.DeadEnd) Elastic.ExprSerialization:
> Elastic.serialize (And [Prefix "big",Or [Word "potatoes",Exact ("french fries")],Exclude (Word "salad")])
"big* (potatoes | \"french fries\") -salad" : String## License
[MIT](https://opensource.org/licenses/MIT)