Dowser.Opensearch.Alias (Dowser.Opensearch v0.1.0)

View Source

The OpenSearch alias APIs — the endpoints tagged Aliases in the OpenSearch OpenAPI specification.

Built on Dowser.Client. Required OpenSearch attributes are positional arguments; everything optional lives in opts.

OpenSearch tags these separately from the index APIs, so they live here rather than on Dowser.Opensearch.Index; the index-target helper they share is Dowser.Opensearch.Target.

OpenSearch serves the single-alias endpoints under both _alias and _aliases; these functions use the singular _alias, which is the form its documentation gives. update_aliases/2 is the separate POST /_aliases endpoint, whose plural is not interchangeable.

Shared conventions

  • An index target may be nil (all indices), a single index/alias/ data-stream name (string or atom), or a list of them (joined with ,). The write endpoints require one and take it as an argument; the reads take it as the :index option.
  • Endpoints that accept a request body take it as their first argument, required — pass %{} to send nothing.
  • HEAD existence checks come as a pair where the ? variant plays the bang role: alias_exists/2 returns {:ok, boolean()} or {:error, exception}, alias_exists?/2 returns the bare boolean (404 → false) and raises on genuine errors.

All remaining options are forwarded to Dowser.Client.request/4, e.g. :context, :params (query-string parameters), :format, :keys and :http_opts (including :headers) — plus :codec, this package's own, which picks the per-field codec for this one request (see Dowser.Opensearch.Codec).

On a 2xx response every function returns {:ok, body} with the decoded response body. A non-2xx response returns {:error, %Dowser.Opensearch.Error{}}; a transport, encoding or decoding failure returns {:error, exception} from Dowser.Client. A required argument that is missing or empty is reported the same way, before any request is made: {:error, %ArgumentError{}}. Each function has a bang variant that returns the body directly or raises the error exception.

Summary

Functions

Checks whether one or several aliases exist (Alias exists API).

Like alias_exists/2, but returns the boolean directly (404 → false) or raises the error exception.

Deletes the alias name from one or several indices (Delete alias API).

Like delete_alias/3, but returns the body directly or raises the error exception.

Returns one, several, or all aliases (Get alias API).

Like get_alias/1, but returns the body directly or raises the error exception.

Creates or updates the alias name on one or several indices (Create or update alias API).

Like put_alias/4, but returns the body directly or raises the error exception.

Applies several alias actions atomically (Alias API).

Like update_aliases/2, but returns the body directly or raises the error exception.

Types

body()

@type body() :: term()

exists_result()

@type exists_result() :: {:ok, boolean()} | {:error, Exception.t()}

index()

@type index() :: Dowser.Opensearch.Target.t()

name()

@type name() :: Dowser.Opensearch.Target.name()

result()

@type result() :: {:ok, body()} | {:error, Exception.t()}

Functions

alias_exists(name, opts \\ [])

@spec alias_exists(name(), keyword()) :: exists_result()

Checks whether one or several aliases exist (Alias exists API).

Returns {:ok, true}, {:ok, false} or {:error, exception}.

Options

  • :index — index target; absent for all indices.

alias_exists?(name, opts \\ [])

@spec alias_exists?(name(), keyword()) :: boolean()

Like alias_exists/2, but returns the boolean directly (404 → false) or raises the error exception.

delete_alias(index, name, opts \\ [])

@spec delete_alias(index(), name(), keyword()) :: result()

Deletes the alias name from one or several indices (Delete alias API).

delete_alias!(index, name, opts \\ [])

@spec delete_alias!(index(), name(), keyword()) :: body()

Like delete_alias/3, but returns the body directly or raises the error exception.

get_alias(opts \\ [])

@spec get_alias(keyword()) :: result()

Returns one, several, or all aliases (Get alias API).

Options

  • :index — index target; absent for all indices.
  • :name — restrict the result to one or several alias names, which may include wildcards.

get_alias!(opts \\ [])

@spec get_alias!(keyword()) :: body()

Like get_alias/1, but returns the body directly or raises the error exception.

put_alias(body, index, name, opts \\ [])

@spec put_alias(map(), index(), name(), keyword()) :: result()

Creates or updates the alias name on one or several indices (Create or update alias API).

body is the request body (e.g. filter, routing, is_write_index); pass %{} to send nothing.

put_alias!(body, index, name, opts \\ [])

@spec put_alias!(map(), index(), name(), keyword()) :: body()

Like put_alias/4, but returns the body directly or raises the error exception.

update_aliases(actions, opts \\ [])

@spec update_aliases([map()], keyword()) :: result()

Applies several alias actions atomically (Alias API).

actions is the list of actions, sent as %{actions: actions}.

This is the endpoint to use when moving an alias: OpenSearch applies the whole list as one atomic step, so a remove-then-add pair never leaves the alias pointing at nothing in between.

Dowser.Opensearch.Alias.update_aliases([
  %{remove: %{index: "posts-v1", alias: "posts"}},
  %{add: %{index: "posts-v2", alias: "posts"}}
])

update_aliases!(actions, opts \\ [])

@spec update_aliases!([map()], keyword()) :: body()

Like update_aliases/2, but returns the body directly or raises the error exception.