Dowser. Opensearch. IndexStateManagement
(Dowser.Opensearch v0.1.0)
View Source
The OpenSearch Index State Management (ISM) APIs — the policy endpoints tagged
Index State Management in the
OpenSearch OpenAPI specification.
Built on Dowser.Client. Required OpenSearch attributes are positional
arguments; everything optional lives in opts.
ISM is an OpenSearch plugin with no Elasticsearch counterpart (it answers the same need as Elastic's ILM). A policy describes an index's lifecycle as a list of states — hot, warm, cold, delete — each with actions to run and transitions to the next; ISM then walks every matching index through them on its own schedule.
What this module covers
The tag bundles three separate plugin features under one name. This module is
the ISM policy API proper — the twelve endpoints under /_plugins/_ism, plus
refresh_search_analyzers/2.
The other two, rollup jobs (/_plugins/_rollup) and transform jobs
(/_plugins/_transform), share the tag but are their own features and are
not covered here yet.
Plugin paths
These endpoints live under /_plugins/_ism. Every one is also served under
the older /_opendistro/_ism prefix, from before the OpenDistro-to-OpenSearch
rename; this module uses /_plugins throughout, which every supported
version serves.
Error bodies
ISM does not always answer with the standard error envelope: some failures
come back as a flat %{"error" => "some message"}. Dowser.Opensearch.Error
recognizes both, so that shape lands in :reason with :type left nil.
Shared conventions
- Endpoints that accept a request body take it as their first argument,
required — pass
%{}to send nothing. :index— the index target the operation applies to, as an option; absent to let the request apply to every managed index.HEADexistence checks come as a pair where the?variant plays the bang role:policy_exists/2returns{:ok, boolean()}or{:error, exception},policy_exists?/2returns 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
Puts indices under the management of a policy (Add policy API).
Like add_policy/2, but returns the body directly or raises the error
exception.
Changes which policy — or which state of it — manages indices (Change policy API).
Like change_policy/2, but returns the body directly or raises the error
exception.
Deletes the policy policy_id
(Delete policy API).
Like delete_policy/2, but returns the body directly or raises the error
exception.
Explains how ISM is managing indices — which policy, which state, and what failed (Explain API).
Like explain_policy/1, but returns the body directly or raises the error
exception.
Returns every policy (Get policies API).
Like get_policies/1, but returns the body directly or raises the error
exception.
Returns the policy policy_id
(Get policy API).
Like get_policy/2, but returns the body directly or raises the error
exception.
Checks whether the policy policy_id exists.
Like policy_exists/2, but returns the boolean directly (404 → false) or
raises the error exception.
Creates or updates several policies in one request (Create policy API).
Like put_policies/2, but returns the body directly or raises the error
exception.
Creates or updates the policy policy_id
(Create policy API).
Like put_policy/3, but returns the body directly or raises the error
exception.
Reloads the search analyzers of one or several indices (Refresh search analyzers API).
Like refresh_search_analyzers/2, but returns the body directly or raises
the error exception.
Removes indices from the management of their policy (Remove policy API).
Like remove_policy/1, but returns the body directly or raises the error
exception.
Retries the failed action of managed indices (Retry failed index API).
Like retry_index/2, but returns the body directly or raises the error
exception.
Types
@type body() :: term()
@type exists_result() :: {:ok, boolean()} | {:error, Exception.t()}
@type index() :: Dowser.Opensearch.Target.t()
@type policy_id() :: Dowser.Opensearch.Target.name()
@type result() :: {:ok, body()} | {:error, Exception.t()}
Functions
Puts indices under the management of a policy (Add policy API).
body names the policy, %{policy_id: "logs-lifecycle"}.
Options
:index— index target; absent to apply to every index the request resolves to.
This attaches the policy as it stands now: the index keeps running that snapshot of it even if the policy is edited afterwards.
Like add_policy/2, but returns the body directly or raises the error
exception.
Changes which policy — or which state of it — manages indices (Change policy API).
body names the new policy and, optionally, which indices it applies to:
%{policy_id: "v2", state: "hot", include: [%{state: "warm"}]}.
This is what moves indices already managed onto an edited policy, which
put_policy/3 alone does not do. The change is queued: ISM applies it when
each index next finishes the action it is in, so a long-running force-merge
finishes first.
Options
:index— index target; absent to apply to every managed index.
Like change_policy/2, but returns the body directly or raises the error
exception.
Deletes the policy policy_id
(Delete policy API).
The indices already managed by it keep running their copy of it until they
are removed from it with remove_policy/1.
Like delete_policy/2, but returns the body directly or raises the error
exception.
Explains how ISM is managing indices — which policy, which state, and what failed (Explain API).
The first place to look when an index is not moving through its policy:
{:ok, explanation} =
Dowser.Opensearch.IndexStateManagement.explain_policy(index: "logs-000001")Options
:index— index target; absent for every managed index.:params— e.g.show_policy: trueto include each policy in full.
Like explain_policy/1, but returns the body directly or raises the error
exception.
Returns every policy (Get policies API).
Options
:params— e.g.from,size,sortField,sortOrder,queryString.
Like get_policies/1, but returns the body directly or raises the error
exception.
Returns the policy policy_id
(Get policy API).
The response carries _seq_no and _primary_term alongside the policy, which
is what put_policy/3 needs to update it.
Like get_policy/2, but returns the body directly or raises the error
exception.
@spec policy_exists(policy_id(), keyword()) :: exists_result()
Checks whether the policy policy_id exists.
Returns {:ok, true}, {:ok, false} or {:error, exception}.
Like policy_exists/2, but returns the boolean directly (404 → false) or
raises the error exception.
Creates or updates several policies in one request (Create policy API).
body is the request body holding the policies to write.
Like put_policies/2, but returns the body directly or raises the error
exception.
Creates or updates the policy policy_id
(Create policy API).
policy is the request body, %{policy: %{...}}:
%{
policy: %{
description: "hot-warm-delete",
default_state: "hot",
states: [
%{name: "hot", actions: [], transitions: [%{state_name: "delete", conditions: %{min_index_age: "30d"}}]},
%{name: "delete", actions: [%{delete: %{}}], transitions: []}
]
}
}
|> Dowser.Opensearch.IndexStateManagement.put_policy("logs-lifecycle")Updating an existing policy needs its current version, passed as
params: [if_seq_no: seq_no, if_primary_term: primary_term] — get_policy/2
returns both. Without them OpenSearch refuses the update rather than
clobbering a concurrent change.
Note that changing a policy does not move the indices already managed by it
onto the new version: change_policy/2 is what does that.
Like put_policy/3, but returns the body directly or raises the error
exception.
Reloads the search analyzers of one or several indices (Refresh search analyzers API).
Picks up changes to the synonym files a search_time analyzer reads, without
closing and reopening the index. Note that this lives under /_plugins
directly rather than under /_plugins/_ism.
Like refresh_search_analyzers/2, but returns the body directly or raises
the error exception.
Removes indices from the management of their policy (Remove policy API).
The endpoint takes no request body.
Options
:index— index target; absent to apply to every managed index.
Like remove_policy/1, but returns the body directly or raises the error
exception.
Retries the failed action of managed indices (Retry failed index API).
body may name the state to retry from, %{state: "warm"}; pass %{} to
retry the action that failed.
An index whose action fails stops there until it is retried — ISM does not
retry on its own past the policy's own retry settings — so this is the way
out once whatever caused the failure is fixed.
Options
:index— index target; absent to retry every failed index.
Like retry_index/2, but returns the body directly or raises the error
exception.