allo-media / elm-es-simple-query-string / 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:

Demo


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

An ElasticSearh expression.

Parser

parse : String -> Result (List Parser.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