Dowser.Opensearch.IndexTemplate (Dowser.Opensearch v0.1.0)

View Source

The OpenSearch index template APIs — the endpoints tagged Index Templates 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 three kinds of template

The tag covers three families, and they are not interchangeable:

  • Index templates (/_index_template) — the composable kind, which can pull shared pieces in through composed_of. This is what to use.
  • Component templates (/_component_template) — the reusable pieces an index template composes. They apply nothing on their own.
  • Legacy templates (/_template) — the pre-composable kind, kept for compatibility. put_template/3 and friends are these; prefer put_index_template/3 for anything new.

A composable index template always wins over a legacy one matching the same pattern, whatever its order.

Shared conventions

  • A template name is a required path parameter, and may be several names (joined with ,) on the read endpoints.
  • 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: index_template_exists/2 returns {:ok, boolean()} or {:error, exception}, index_template_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 the component template name exists.

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

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

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

Deletes the legacy index template name (Delete template API).

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

Returns one, several, or all component templates (Get component template API).

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

Returns one, several, or all index templates (Get index template API).

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

Returns one, several, or all legacy index templates (Get template API).

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

Checks whether the index template name exists.

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

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

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

Creates or updates the legacy index template name (Create or update template API).

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

Simulates applying the matching index templates to the index name (Simulate index API).

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

Simulates the resolved composition of an index template (Simulate template API).

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

Checks whether the legacy index template name exists.

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

Types

body()

@type body() :: term()

exists_result()

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

name()

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

result()

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

Functions

component_template_exists(name, opts \\ [])

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

Checks whether the component template name exists.

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

component_template_exists?(name, opts \\ [])

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

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

delete_component_template(name, opts \\ [])

@spec delete_component_template(name(), keyword()) :: result()

Deletes the component template name (Delete component template API).

delete_component_template!(name, opts \\ [])

@spec delete_component_template!(name(), keyword()) :: body()

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

delete_index_template(name, opts \\ [])

@spec delete_index_template(name(), keyword()) :: result()

Deletes the index template name (Delete index template API).

delete_index_template!(name, opts \\ [])

@spec delete_index_template!(name(), keyword()) :: body()

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

delete_template(name, opts \\ [])

@spec delete_template(name(), keyword()) :: result()

Deletes the legacy index template name (Delete template API).

delete_template!(name, opts \\ [])

@spec delete_template!(name(), keyword()) :: body()

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

get_component_template(opts \\ [])

@spec get_component_template(keyword()) :: result()

Returns one, several, or all component templates (Get component template API).

Options

  • :name — restrict the result to one or several template names; absent for all of them.

get_component_template!(opts \\ [])

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

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

get_index_template(opts \\ [])

@spec get_index_template(keyword()) :: result()

Returns one, several, or all index templates (Get index template API).

Options

  • :name — restrict the result to one or several template names, which may include wildcards; absent for all of them.

get_index_template!(opts \\ [])

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

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

get_template(opts \\ [])

@spec get_template(keyword()) :: result()

Returns one, several, or all legacy index templates (Get template API).

Options

  • :name — restrict the result to one or several template names; absent for all of them.

get_template!(opts \\ [])

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

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

index_template_exists(name, opts \\ [])

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

Checks whether the index template name exists.

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

index_template_exists?(name, opts \\ [])

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

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

put_component_template(template, name, opts \\ [])

@spec put_component_template(map(), name(), keyword()) :: result()

Creates or updates the component template name (Create or update component template API).

template is the request body, e.g. %{template: %{settings: %{...}}}. A component template applies nothing by itself: name it in an index template's composed_of to have it take effect.

put_component_template!(template, name, opts \\ [])

@spec put_component_template!(map(), name(), keyword()) :: body()

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

put_index_template(template, name, opts \\ [])

@spec put_index_template(map(), name(), keyword()) :: result()

Creates or updates the index template name (Create or update index template API).

template is the request body, e.g. %{index_patterns: ["posts-*"], template: %{...}}.

%{index_patterns: ["logs-*"], template: %{settings: %{number_of_shards: 1}}}
|> Dowser.Opensearch.IndexTemplate.put_index_template("logs")

put_index_template!(template, name, opts \\ [])

@spec put_index_template!(map(), name(), keyword()) :: body()

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

put_template(template, name, opts \\ [])

@spec put_template(map(), name(), keyword()) :: result()

Creates or updates the legacy index template name (Create or update template API).

template is the request body, e.g. %{index_patterns: ["posts-*"], settings: %{...}}.

This is the pre-composable /_template endpoint; prefer put_index_template/3 for anything new.

put_template!(template, name, opts \\ [])

@spec put_template!(map(), name(), keyword()) :: body()

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

simulate_index_template(body, name, opts \\ [])

@spec simulate_index_template(map(), name(), keyword()) :: result()

Simulates applying the matching index templates to the index name (Simulate index API).

body is an optional template body to simulate alongside the existing ones; pass %{} to send nothing. name is the index name to simulate the creation of, not a template name.

simulate_index_template!(body, name, opts \\ [])

@spec simulate_index_template!(map(), name(), keyword()) :: body()

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

simulate_template(body, opts \\ [])

@spec simulate_template(map(), keyword()) :: result()

Simulates the resolved composition of an index template (Simulate template API).

body is a template body to simulate instead of a stored one; pass %{} to send nothing.

Options

  • :name — a stored template to resolve, appended to the path; absent to resolve the body alone.

simulate_template!(body, opts \\ [])

@spec simulate_template!(map(), keyword()) :: body()

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

template_exists(name, opts \\ [])

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

Checks whether the legacy index template name exists.

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

template_exists?(name, opts \\ [])

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

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