View Source ExlasticSearch.Query (exlasticsearch v2.3.0)

Elasticsearch query building functions.

Basic usage for queryable Queryable is something like:

Queryable.search_query()
|> must(match(field, value))
|> should(match_phrase(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.

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 running 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.

Types

field()

@type field() :: String.t() | atom()

t()

@type t() :: %ExlasticSearch.Query{
  filter: term(),
  index_type: term(),
  must: term(),
  must_not: term(),
  options: term(),
  queryable: term(),
  should: term(),
  sort: term(),
  type: term()
}

Functions

field_value_factor(query, fvf, opts \\ [])

@spec field_value_factor(t(), term(), Keyword.t()) :: t()

filter(query, filter)

@spec filter(t(), map()) :: t()

Appends a new filter scope to the running query.

function_score(query, functions, opts \\ [])

@spec function_score(t(), [term()], Keyword.t()) :: t()

ids(ids)

@spec ids(list()) :: map()

ids query clause.

match(field, query)

@spec match(field(), String.t()) :: map()

Builds a match query clause.

match(field, query, opts)

@spec match(field(), String.t(), Keyword.t()) :: map()

match_phrase(field, query, opts \\ [])

@spec match_phrase(field(), String.t(), Keyword.t()) :: map()

Builds a match phrase query clause.

multi_match(fields, query, opts \\ [])

@spec multi_match([field()], String.t(), Keyword.t()) :: map()

Multimatch query clause.

must(query, must)

@spec must(t(), map()) :: t()

Appends a new must scope to the running query.

must_not(query, must_not)

@spec must_not(t(), map()) :: t()

Appends a new must_not scope to the running query.

nested(query, path)

@spec nested(t(), term()) :: t()

options(query, opts)

@spec options(t(), map() | Keyword.t()) :: t()

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

query_string(query, opts \\ [])

@spec query_string(String.t(), Keyword.t()) :: map()

Query string query type, that applies ES standard query rewriting.

range(field, range)

@spec range(field(), map()) :: map()

Range query clause.

realize(query)

@spec realize(t()) :: map()

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

script_score(query, script, opts \\ [])

@spec script_score(t(), String.t(), Keyword.t()) :: t()

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

should(query, should)

@spec should(t(), map()) :: t()

Appends a new should scope to the running query.

sort(query, field, direction \\ "asc")

@spec sort(t(), field(), String.t() | atom()) :: t()

Adds a sort clause to the ES query.

term(field, term)

@spec term(field(), term()) :: map()

Term query clause.

terms(field, terms)

@spec terms(field(), [term()]) :: map()

Terms query clause.