Dowser.Opensearch.Cluster (Dowser.Opensearch v0.1.0)

View Source

The OpenSearch cluster APIs — every endpoint tagged Cluster in the OpenSearch OpenAPI specification (health, state, settings, routing and the awareness controls).

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

For the node name, cluster name and version, see Dowser.Opensearch.Info.info/1 (GET /).

Shared conventions

  • Endpoints that accept a request body take it as their first argument, required — pass %{} to send nothing.
  • Optional path parameters are options (:index, :metric, :node_id). Where OpenSearch reads one segment as the position after another — state/1's index after its metric — naming the inner one without the outer is an ArgumentError rather than a silently wrong path.

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

Explains why a shard is or is not allocated where it is (Cluster allocation explain API).

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

Recommissions every decommissioned zone (Decommission API).

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

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

Clears the weighted routing configuration (Weighted routing API).

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

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

Returns the cluster settings (Cluster settings API).

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

Returns the weights of an awareness attribute's zones (Weighted routing API).

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

Returns the health of the cluster, or of one or several indices (Cluster health API).

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

Returns the cluster-level changes not yet executed (Pending tasks API).

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

Excludes nodes from the voting configuration (Voting configuration exclusions API).

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

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

Sets the search-traffic weights of an awareness attribute's zones (Weighted routing API).

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

Returns the configured remote clusters (Remote cluster info API).

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

Moves, allocates or cancels shards by hand (Cluster reroute API).

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

Returns the cluster state — the metadata the cluster manager holds (Cluster state API).

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

Returns cluster-wide statistics — indices, nodes, shards, and the plugins installed (Cluster stats API).

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

Types

body()

@type body() :: term()

index()

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

name()

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

result()

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

Functions

allocation_explain(body, opts \\ [])

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

Explains why a shard is or is not allocated where it is (Cluster allocation explain API).

body names the shard to explain, e.g. %{index: "posts", shard: 0, primary: true}; pass %{} to have OpenSearch pick the first unassigned shard it finds — which is usually the one you are asking about.

allocation_explain!(body, opts \\ [])

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

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

delete_decommission_awareness(opts \\ [])

@spec delete_decommission_awareness(keyword()) :: result()

Recommissions every decommissioned zone (Decommission API).

As with delete_weighted_routing/1, OpenSearch serves this on the unscoped path, so it clears every decommission rather than one attribute's.

delete_decommission_awareness!(opts \\ [])

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

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

delete_voting_config_exclusions(opts \\ [])

@spec delete_voting_config_exclusions(keyword()) :: result()

Clears the voting configuration exclusions (Voting configuration exclusions API).

delete_voting_config_exclusions!(opts \\ [])

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

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

delete_weighted_routing(opts \\ [])

@spec delete_weighted_routing(keyword()) :: result()

Clears the weighted routing configuration (Weighted routing API).

Note that OpenSearch serves the delete on the unscoped path, with no attribute segment — so this clears the whole configuration rather than one attribute's.

delete_weighted_routing!(opts \\ [])

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

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

get_decommission_awareness(awareness_attribute_name, opts \\ [])

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

Returns the status of a zone decommission (Decommission API).

get_decommission_awareness!(awareness_attribute_name, opts \\ [])

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

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

get_settings(opts \\ [])

@spec get_settings(keyword()) :: result()

Returns the cluster settings (Cluster settings API).

Options

  • :params — e.g. include_defaults: true to see the settings nobody has changed, which is otherwise omitted.

get_settings!(opts \\ [])

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

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

get_weighted_routing(attribute, opts \\ [])

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

Returns the weights of an awareness attribute's zones (Weighted routing API).

get_weighted_routing!(attribute, opts \\ [])

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

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

health(opts \\ [])

@spec health(keyword()) :: result()

Returns the health of the cluster, or of one or several indices (Cluster health API).

Options

  • :index — index target; absent for the whole cluster.
  • :params — e.g. level, wait_for_status, timeout.

wait_for_status is what makes this endpoint useful in a setup script: it blocks until the cluster reaches the status asked for, or the timeout elapses.

Dowser.Opensearch.Cluster.health!(params: [wait_for_status: "yellow", timeout: "30s"])

health!(opts \\ [])

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

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

pending_tasks(opts \\ [])

@spec pending_tasks(keyword()) :: result()

Returns the cluster-level changes not yet executed (Pending tasks API).

pending_tasks!(opts \\ [])

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

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

post_voting_config_exclusions(opts \\ [])

@spec post_voting_config_exclusions(keyword()) :: result()

Excludes nodes from the voting configuration (Voting configuration exclusions API).

The nodes to exclude are named through :params — node_names or node_ids. This is the step before removing cluster-manager-eligible nodes, so the remaining ones can still elect a manager.

post_voting_config_exclusions!(opts \\ [])

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

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

put_decommission_awareness(awareness_attribute_name, awareness_attribute_value, opts \\ [])

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

Decommissions a zone, taking its nodes out of the cluster (Decommission API).

An OpenSearch addition with no Elasticsearch counterpart. awareness_attribute_name is the attribute (typically "zone") and awareness_attribute_value the zone to decommission.

Weight the zone down with put_weighted_routing/3 first: decommissioning moves traffic off its nodes and then excludes them, and doing it to a zone still taking searches drops the ones in flight.

put_decommission_awareness!(awareness_attribute_name, awareness_attribute_value, opts \\ [])

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

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

put_settings(settings, opts \\ [])

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

Updates the cluster settings (Cluster settings API).

settings is the settings body, under persistent or transient:

%{persistent: %{"cluster.routing.allocation.enable" => "all"}}
|> Dowser.Opensearch.Cluster.put_settings()

persistent survives a full cluster restart, transient does not. Setting a value to nil resets it to its default.

put_settings!(settings, opts \\ [])

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

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

put_weighted_routing(body, attribute, opts \\ [])

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

Sets the search-traffic weights of an awareness attribute's zones (Weighted routing API).

An OpenSearch addition with no Elasticsearch counterpart. attribute is the awareness attribute (typically "zone"), and body the weights, e.g. %{weights: %{"us-east-1a" => "1", "us-east-1b" => "0"}} — a weight of 0 takes a zone out of search rotation without removing its nodes.

put_weighted_routing!(body, attribute, opts \\ [])

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

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

remote_info(opts \\ [])

@spec remote_info(keyword()) :: result()

Returns the configured remote clusters (Remote cluster info API).

Note the path: this one endpoint lives at /_remote/info, not under /_cluster.

remote_info!(opts \\ [])

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

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

reroute(body, opts \\ [])

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

Moves, allocates or cancels shards by hand (Cluster reroute API).

body is the request body, typically %{commands: [...]}; pass %{} to let OpenSearch retry the allocations it had given up on.

Use params: [dry_run: true] to see what the commands would do without applying them, and params: [explain: true] for why each one was accepted or rejected.

reroute!(body, opts \\ [])

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

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

state(opts \\ [])

@spec state(keyword()) :: result()

Returns the cluster state — the metadata the cluster manager holds (Cluster state API).

Options

  • :metric — restrict the state to one or several metrics (metadata, routing_table, nodes, …).
  • :index — index target. OpenSearch reads it as the segment after the metric, so it needs one: passing an index with no metric is an ArgumentError. Use metric: "_all" to ask for everything.

The full state of a large cluster is a big document; naming a metric is usually what you want.

state!(opts \\ [])

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

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

stats(opts \\ [])

@spec stats(keyword()) :: result()

Returns cluster-wide statistics — indices, nodes, shards, and the plugins installed (Cluster stats API).

Options

  • :node_id — restrict the statistics to one or several nodes.

stats!(opts \\ [])

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

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