Dowser. Elasticsearch. Search
(Dowser.Elasticsearch v0.1.0)
View Source
The Elasticsearch search APIs — every endpoint tagged search in the
Elasticsearch OpenAPI specification.
Built on Dowser.Client. Required Elasticsearch attributes are positional
arguments; everything optional lives in opts. Request bodies come first so
they pipe naturally.
Shared conventions
:index— where the endpoint accepts an optional index target:nil/absent for all indices, a single index string, or a list of index strings (joined with,). Endpoints that require an index take it as the first argument instead.- Endpoints that accept a request body take it as their first argument,
required — pass
%{}to send nothing. The argument is namedquerywhen the body is an Elasticsearch query DSL document, andbody(or a more specific name such astemplateorsearches) otherwise. - When Elasticsearch serves an operation over both
GETandPOST, the request usesPOSTwhenever a body is present andGETotherwise.
All remaining options are forwarded to Dowser.Client.request/4, e.g.
:config, :params (query-string parameters), :format, :http_adapter,
:json_adapter and :http_opts (including :headers).
Values are cast automatically wherever :codec_adapter is set to
Dowser.Elasticsearch.TypeCodec — no per-call option needed.
On a 2xx response every function returns {:ok, body} with the decoded
response body. A non-2xx response returns
{:error, %Dowser.Elasticsearch.Error{}}; a transport, encoding or decoding
failure returns {:error, exception} from Dowser.Client. Each function has
a bang variant that returns the body directly or raises the error exception.
Summary
Functions
Releases one or several scroll contexts (Clear scroll API).
Like clear_scroll/2, but returns the body directly or raises the error
exception.
Closes the point in time id
(Close point in time API).
Like close_point_in_time/2, but returns the body directly or raises the
error exception.
Counts the documents matching a query (Count API).
Like count/2, but returns the body directly or raises the error exception.
Cancels the async search id and deletes its results
(Delete async search API).
Like delete_async_search/2, but returns the body directly or raises the
error exception.
Explains whether and how the document id in index matches a query
(Explain API).
Like explain/4, but returns the body directly or raises the error exception.
Returns the capabilities of fields across indices (Field capabilities API).
Like field_caps/2, but returns the body directly or raises the error
exception.
Retrieves the results of the async search id
(Get async search API).
Like get_async_search/2, but returns the body directly or raises the error
exception.
Retrieves the status of the async search id, without its results
(Get async search status API).
Like get_async_search_status/2, but returns the body directly or raises the
error exception.
Runs several searches in one request (Multi search API).
Like msearch/2, but returns the body directly or raises the error exception.
Runs several template searches in one request (Multi search template API).
Like msearch_template/2, but returns the body directly or raises the error
exception.
Opens a point in time over index for use in later searches
(Open point in time API).
Like open_point_in_time/4, but returns the body directly or raises the
error exception.
Evaluates the quality of ranked search results over a set of typical queries (Ranking evaluation API).
Like rank_eval/2, but returns the body directly or raises the error
exception.
Renders the stored search template id into an actual search body
(Render search template API).
Like render_search_template/3, but returns the body directly or raises the
error exception.
Fetches the next page of a scrolling search (Scroll API).
Like scroll/2, but returns the body directly or raises the error exception.
Runs a search against one, several, or all indices (Search API).
Like search/2, but returns the body directly or raises the error exception.
Searches a vector tile for geospatial values (Vector tile search API).
Like search_mvt/7, but returns the body directly or raises the error
exception.
Returns the indices and shards a search would run against (Search shards API).
Like search_shards/1, but returns the body directly or raises the error
exception.
Runs a search with a stored or inline search template (Search template API).
Like search_template/2, but returns the body directly or raises the error
exception.
Submits a search that runs asynchronously (Submit async search API).
Like submit_async_search/2, but returns the body directly or raises the
error exception.
Enumerates the terms of a field that match a partial string (Terms enum API).
Like terms_enum/3, but returns the body directly or raises the error
exception.
Types
@type body() :: term()
@type id() :: String.t()
@type index() :: Dowser.Elasticsearch.Index.t()
@type query() :: map()
@type result() :: {:ok, body()} | {:error, Exception.t()}
Functions
Releases one or several scroll contexts (Clear scroll API).
scroll_id is a scroll id, a list of scroll ids, or "_all".
Like clear_scroll/2, but returns the body directly or raises the error
exception.
Closes the point in time id
(Close point in time API).
Like close_point_in_time/2, but returns the body directly or raises the
error exception.
Counts the documents matching a query (Count API).
query is the count body (query DSL map); pass %{} to count everything.
Options
:index— index target; absent for all indices.
Like count/2, but returns the body directly or raises the error exception.
Cancels the async search id and deletes its results
(Delete async search API).
Like delete_async_search/2, but returns the body directly or raises the
error exception.
Explains whether and how the document id in index matches a query
(Explain API).
query is the explain body (query DSL map).
Like explain/4, but returns the body directly or raises the error exception.
Returns the capabilities of fields across indices (Field capabilities API).
body is the request body, e.g.
%{fields: ["title"], index_filter: %{...}}.
Options
:index— index target; absent for all indices.
Like field_caps/2, but returns the body directly or raises the error
exception.
Retrieves the results of the async search id
(Get async search API).
Like get_async_search/2, but returns the body directly or raises the error
exception.
Retrieves the status of the async search id, without its results
(Get async search status API).
Like get_async_search_status/2, but returns the body directly or raises the
error exception.
Runs several searches in one request (Multi search API).
searches is a flat list alternating header and body maps, encoded as
NDJSON:
Dowser.Elasticsearch.Search.msearch([
%{},
%{query: %{match_all: %{}}},
%{index: "comments"},
%{query: %{match: %{body: "hello"}}}
])Options
:index— default index target for searches whose header has none.
Like msearch/2, but returns the body directly or raises the error exception.
Runs several template searches in one request (Multi search template API).
searches is a flat list alternating header and template-body maps, encoded
as NDJSON (see msearch/2).
Options
:index— default index target for searches whose header has none.
Like msearch_template/2, but returns the body directly or raises the error
exception.
Opens a point in time over index for use in later searches
(Open point in time API).
body is the request body (e.g. index_filter); pass %{} to send
nothing. keep_alive is how long the point in time is kept alive, e.g.
"1m"; it is sent as the required keep_alive query-string parameter.
Like open_point_in_time/4, but returns the body directly or raises the
error exception.
Evaluates the quality of ranked search results over a set of typical queries (Ranking evaluation API).
requests is the list of rated requests.
Options
:index— index target; absent for all indices.:metric— the evaluation metric, merged into the body alongsiderequests.
Like rank_eval/2, but returns the body directly or raises the error
exception.
Renders the stored search template id into an actual search body
(Render search template API).
template is the request body, typically %{params: %{...}}.
Like render_search_template/3, but returns the body directly or raises the
error exception.
Fetches the next page of a scrolling search (Scroll API).
Sends scroll_id in the request body, the form Elasticsearch recommends.
Options
:scroll— how long to keep the scroll context alive, e.g."1m"; merged into the body.
Like scroll/2, but returns the body directly or raises the error exception.
Runs a search against one, several, or all indices (Search API).
query is the search body (the Elasticsearch query DSL as a map); pass %{}
to match everything. It comes first so it can be piped:
%{query: %{match: %{title: "hello"}}}
|> Dowser.Elasticsearch.Search.search(index: "posts")Every key in the response is cast per :keys. Wherever :type_codec is
configured (see Dowser.Elasticsearch.TypeCodec), each hit's _source is
additionally cast against its own index mapping (dates become DateTime,
IPs become :inet tuples, and so on) — automatically, at any nesting
depth, so msearch/2, search_template/2, scroll/2 and the rest get the
same treatment with no extra options.
Options
:index—nil/absent for all indices, a single index string, or a list of index strings (joined with,).
Like search/2, but returns the body directly or raises the error exception.
@spec search_mvt( map(), index(), String.t(), integer(), integer(), integer(), keyword() ) :: result()
Searches a vector tile for geospatial values (Vector tile search API).
body is the request body (e.g. query, fields, grid_agg); pass %{}
to send nothing. Returns the binary Mapbox vector tile, so the response
format defaults to :raw (override with :resp_format/:format).
@spec search_mvt!( map(), index(), String.t(), integer(), integer(), integer(), keyword() ) :: body()
Like search_mvt/7, but returns the body directly or raises the error
exception.
Returns the indices and shards a search would run against (Search shards API).
Options
:index— index target; absent for all indices.
Like search_shards/1, but returns the body directly or raises the error
exception.
Runs a search with a stored or inline search template (Search template API).
template is the request body, e.g. %{id: "my-template", params: %{...}}
or %{source: %{...}, params: %{...}}.
Options
:index— index target; absent for all indices.
Like search_template/2, but returns the body directly or raises the error
exception.
Submits a search that runs asynchronously (Submit async search API).
query is the search body, exactly as in search/2.
Options
:index— index target; absent for all indices.
Like submit_async_search/2, but returns the body directly or raises the
error exception.
Enumerates the terms of a field that match a partial string (Terms enum API).
body is the request body and must include field, e.g.
%{field: "title", string: "he"}.
Like terms_enum/3, but returns the body directly or raises the error
exception.