Dowser. Elasticsearch. Repository
(Dowser.Elasticsearch v0.1.0)
View Source
The repository pattern: binds the index-related API functions to a fixed or computed index.
defmodule Probes do
use Dowser.Elasticsearch.Repository,
only: [search: [:msearch, :search]],
index: &index_name/1
def index_name(term) do
"my_index_#{term}"
end
end
%{query: %{match_all: %{}}} |> Probes.search(index: "day1")
# searches my_index_day1Options
:index(required) — where the repository points:- a string or atom (or a list of them): a static index. Index
arguments disappear from the generated functions entirely —
Probes.get("1"),Probes.search(query)— and any:indexoption passed by the caller is overwritten. - a 1-arity function capture (or
fn): a dynamic index. Wherever the underlying API takes an index, the generated function takes a term instead — positionally (Probes.get(term, "1")) or as the:indexoption (Probes.search(query, index: term),nilwhen absent) — and the function turns the term into the actual index.
- a string or atom (or a list of them): a static index. Index
arguments disappear from the generated functions entirely —
:only/:except— mutually exclusive filters over the generated functions. Each entry is either a module key alone to select every function of that module, orkey: [:fun, ...]for specific ones. Module keys::search(Dowser.Elasticsearch.Search),:document(Dowser.Elasticsearch.Document) and:index(Dowser.Elasticsearch.Index). Base names select their!/?variants too. Without:only/:except, every index-related function of all three modules is generated.
Only index-related functions can be generated; functions that do not target
an index (reindex, scroll, templates, …) never are — call their module
directly.
Summary
Functions
Resolves a repository :index configuration against a term: calls it when
it is a 1-arity function, returns it unchanged otherwise.
Functions
@spec resolve_index(term(), term()) :: Dowser.Elasticsearch.Index.t()
Resolves a repository :index configuration against a term: calls it when
it is a 1-arity function, returns it unchanged otherwise.