Dowser.Elasticsearch.Reindex (Dowser.Elasticsearch v0.4.1)

View Source

The Elasticsearch reindex task APIs — every endpoint tagged reindex in the Elasticsearch OpenAPI specification: listing the reindex tasks that are running, following one, and cancelling one.

These track a reindex; they don't start one. The reindex itself is Dowser.Elasticsearch.Document.reindex/2 (POST /_reindex), which the specification tags document, and so is its Dowser.Elasticsearch.Document.reindex_rethrottle/3. Run it with params: [wait_for_completion: false] to get back the task these functions take.

A task is followed by its id across node-shutdown relocations, so the id the reindex returned stays the one to ask about for the lifetime of the operation.

Built on Dowser.Client. The task id is a positional argument where the endpoint requires one; everything optional lives in opts.

All options are forwarded to Dowser.Client.request/4, e.g. :context, :params (query-string parameters), :format, :keys and :http_opts (including :headers).

On a 2xx response every function returns {:ok, body} with the decoded response body. A non-2xx response returns {:error, %Dowser.Elasticsearch.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

Types

A reindex task id, as returned by POST /_reindex.

Functions

Cancels the reindex task task_id — POST /_reindex/{task_id}/_cancel (Cancel reindex task API).

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

Returns the status and progress of the reindex task task_id — GET /_reindex/{task_id} (Get reindex task API).

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

Lists the reindex tasks currently running — GET /_reindex (List reindex tasks API).

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

Types

body()

@type body() :: term()

result()

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

task_id()

@type task_id() :: String.t() | atom()

A reindex task id, as returned by POST /_reindex.

Functions

cancel(task_id, opts \\ [])

@spec cancel(task_id(), keyword()) :: result()

Cancels the reindex task task_id — POST /_reindex/{task_id}/_cancel (Cancel reindex task API).

The documents already reindexed stay where they are; cancelling stops the task from writing any more.

Options

  • :params — wait_for_completion is true by default, and the response is the task's final state after cancellation; false answers acknowledged: true right away.

cancel!(task_id, opts \\ [])

@spec cancel!(task_id(), keyword()) :: body()

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

get(task_id, opts \\ [])

@spec get(task_id(), keyword()) :: result()

Returns the status and progress of the reindex task task_id — GET /_reindex/{task_id} (Get reindex task API).

{:ok, task} = Dowser.Elasticsearch.Reindex.get("node-1:12345")
task["completed"]
#=> false

Options

  • :params — wait_for_completion: true waits for the task to finish before answering, timeout caps that wait.

get!(task_id, opts \\ [])

@spec get!(task_id(), keyword()) :: body()

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

list(opts \\ [])

@spec list(keyword()) :: result()

Lists the reindex tasks currently running — GET /_reindex (List reindex tasks API).

A task mid-relocation between nodes is reported once, under its original id, so a relocation never shows up as a duplicate.

Options

  • :params — detailed: true adds each task's progress and sub-tasks.

list!(opts \\ [])

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

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