exlasticsearch v1.10.1 ExlasticSearch.Query View Source

Elasticsearch query building functions. Basic usage for queryable Queryable is something like:

Queryable.search_query()
|> must(math(field, value))
|> should(match_phrash(field, value, opts))
|> filter(term(filter_field, value))
|> realize()

An ES query has 3 main clauses, must, should and filter. Must and should are near equivalents except that must clauses will reject records that fail to match. Filters require matches but do not contribute to scoring, while must/should both do. Nesting queries within queries is also supported

Currently the module only supports the boolean style of compound query, but we could add support for the others as need be.

See https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html for documentation on specific query types.

Link to this section Summary

Functions

Appends a new filter scope to the running query

ids query clause

Builds a match query clause

Builds a match phrase query clause

Multimatch query clause

Appends a new must scope to the runnning query

Appends a new must_not scope to the running query

Add options to the current bool compound query (for instance the minimum number of accepted matches)

Query string query type, that applies ES standard query rewriting

range query clause

Converts a Query struct into an ES compliant bool or function score compound query

Converts a query to a function score query and adds the given script for scoring

Appends a new should scope to the running query

Adds a sort clause to the ES query

Term query clause

terms query clause

Link to this section Types

Link to this type t() View Source
t() :: %ExlasticSearch.Query{
  filter: term(),
  index_type: term(),
  must: term(),
  must_not: term(),
  options: term(),
  queryable: term(),
  should: term(),
  sort: term(),
  type: term()
}

Link to this section Functions

Link to this function field_value_factor(q, fvf, opts \\ []) View Source
Link to this function filter(query, filter) View Source
filter(t(), map()) :: t()

Appends a new filter scope to the running query

Link to this function function_score(q, functions, opts \\ []) View Source

ids query clause

Link to this function match(field, query) View Source
match(atom(), binary()) :: map()

Builds a match query clause

Link to this function match(field, query, opts) View Source
Link to this function match_phrase(field, query, opts \\ []) View Source
match_phrase(atom(), binary(), list()) :: map()

Builds a match phrase query clause

Link to this function multi_match(fields, query, opts \\ []) View Source

Multimatch query clause

Link to this function must(query, must) View Source
must(t(), map()) :: t()

Appends a new must scope to the runnning query

Link to this function must_not(query, must_not) View Source
must_not(t(), map()) :: t()

Appends a new must_not scope to the running query

Link to this function options(query, opts) View Source
options(t(), map()) :: t()

Add options to the current bool compound query (for instance the minimum number of accepted matches)

Link to this function query_string(query, opts \\ []) View Source
query_string(atom(), binary()) :: map()

Query string query type, that applies ES standard query rewriting

Link to this function range(field, range) View Source
range(atom(), map()) :: map()

range query clause

Link to this function realize(query) View Source
realize(t()) :: map()

Converts a Query struct into an ES compliant bool or function score compound query

Link to this function script_score(q, script, opts \\ []) View Source

Converts a query to a function score query and adds the given script for scoring

Link to this function should(query, should) View Source
should(t(), map()) :: t()

Appends a new should scope to the running query

Link to this function sort(query, field, direction \\ "asc") View Source
sort(t(), binary() | atom(), binary()) :: t()

Adds a sort clause to the ES query

Link to this function term(field, term) View Source
term(atom(), binary()) :: map()

Term query clause

Link to this function terms(field, terms) View Source
terms(atom(), binary()) :: map()

terms query clause