Dowser. Opensearch. Repository
(Dowser.Opensearch 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.Opensearch.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
OpenSearch spreads the index APIs over more tags than Elasticsearch does, so
there are more keys here than the three of dowser_elasticsearch:
| key | module |
|---|---|
:document | Dowser.Opensearch.Document |
:index | Dowser.Opensearch.Index |
:search | Dowser.Opensearch.Search |
:mappings | Dowser.Opensearch.Mappings |
:index_settings | Dowser.Opensearch.IndexSettings |
:alias | Dowser.Opensearch.Alias |
:reindex | Dowser.Opensearch.Reindex |
:cat | Dowser.Opensearch.Cat |
:list | Dowser.Opensearch.List |
:ism | Dowser.Opensearch.IndexStateManagement |
Base names select their !/? variants too. Without :only/:except,
every index-related function of all ten modules is generated.
Two functions selected from different modules can end up sharing the same
base name — count is both a search and a cat endpoint, indices both a cat
and a list one. renames/0 below is a fixed table renaming such functions
(!/? variants follow the rename); use raises an ArgumentError naming
the clash if it finds one that renames/0 does not cover, so the fix is to
add an entry there rather than to work around it at the call site.
Only index-related functions can be generated; functions that do not target
an index (reindex, scroll, templates, the cluster APIs, the ISM policy
CRUD, …) 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.Opensearch.Target.t()
Resolves a repository :index configuration against a term: calls it when
it is a 1-arity function, returns it unchanged otherwise.