Packages

Steroids is an ElasticSearch query body builder adapted from [Bodybuilder](https://github.com/danpaz/bodybuilder). Easily build complex queries for elasticsearch with a simple, predictable api.

Current section

Files

Jump to
steroids lib bool_query.ex
Raw

lib/bool_query.ex

defmodule Steroids.BoolQuery do
@valid_conditions [:must, :must_not, :should]
@spec new(atom, map) :: {:bool, atom, atom, map}
def new(field, clause), do: {:bool, field, cond_atom(:and), clause}
def new(condition, field, clause), do: {:bool, field, cond_atom(condition), clause}
defp cond_atom(:mustNot), do: :must_not
defp cond_atom(:and), do: :must
defp cond_atom(:or), do: :should
defp cond_atom(:not), do: :must_not
defp cond_atom(val) when val in @valid_conditions, do: val
defp cond_atom(_), do: :must
end