allo-media/elm-es-simple-query-string/4.0.0

Elastic

Parse and serialize ElasticSearch search query strings.

This package allows to parse an elastic simple query string into an AST, and serialize string search queries out of it.

Notes:

  • \r, \n and \t characters will be considered as blank spaces.
  • Serialization will enforce classic boolean operator precedence by using parenthesis groups everywhere applicable.

Demo

type Expr
= And (List Expr)
| Exact String
| Exclude Expr
| Fuzzy Int String
| Or (List Expr)
| Prefix String
| Word String

An ElasticSearh expression.

Parser

parse : String -> Result (List DeadEnd) Expr

Parse an ElasticSearch search query string and convert it into an Expr.

Serializer

serialize : Expr -> String

Serialize an Expr to an ElasticSearch query string.

Note: Operator precedence will be enforced by the use of parenthesis groups everywhere applicable. That also means this function might act as a formatter as well as a sanitizer:

> " a  b  |c  d  " |> parse |> Result.map serialize
Ok ("(a b) | (c d)") : Result (List Parser.DeadEnd) String