Dowser.Opensearch.Reindex (Dowser.Opensearch v0.1.0)

View Source

The OpenSearch reindex and by-query APIs — the endpoints tagged Reindex in the OpenSearch OpenAPI specification.

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

OpenSearch groups _reindex, _delete_by_query and _update_by_query under one tag, along with the _rethrottle endpoint each of them has, so they all live here — where Elasticsearch tags them as document APIs.

Shared conventions

  • Endpoints that accept a request body take it as their first argument, required — pass %{} to send nothing. The argument is named query when the body is an OpenSearch query DSL document and body otherwise.
  • The by-query endpoints require an index target, so they take it as an argument rather than an option.

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).

None of these endpoints is marked retryable: each one writes, and a _reindex or _update_by_query that timed out may well have applied part of its work, so re-sending it would redo that part. Pass retry: [idempotent: true] to override that for a call you know is safe to repeat.

Running long operations in the background

Every endpoint here can take longer than a request should, so OpenSearch accepts params: [wait_for_completion: false] on all of them: the response is then a task id, which _tasks reports on and the *_rethrottle functions below can slow down or speed up.

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

Deletes every document matching a query (Delete by query API).

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

Changes the throttling of the running delete-by-query task task_id (Delete by query rethrottle API).

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

Copies documents from one index to another (Reindex API).

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

Changes the throttling of the running reindex task task_id (Reindex rethrottle API).

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

Updates every document matching a query (Update by query API).

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

Changes the throttling of the running update-by-query task task_id (Update by query rethrottle API).

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

Types

body()

@type body() :: term()

id()

@type id() :: String.t()

index()

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

result()

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

Functions

delete_by_query(query, index, opts \\ [])

@spec delete_by_query(map(), index(), keyword()) :: result()

Deletes every document matching a query (Delete by query API).

query is the delete body (query DSL map).

delete_by_query!(query, index, opts \\ [])

@spec delete_by_query!(map(), index(), keyword()) :: body()

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

delete_by_query_rethrottle(task_id, requests_per_second, opts \\ [])

@spec delete_by_query_rethrottle(id(), number(), keyword()) :: result()

Changes the throttling of the running delete-by-query task task_id (Delete by query rethrottle API).

requests_per_second is sent as the required query-string parameter.

delete_by_query_rethrottle!(task_id, requests_per_second, opts \\ [])

@spec delete_by_query_rethrottle!(id(), number(), keyword()) :: body()

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

reindex(body, opts \\ [])

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

Copies documents from one index to another (Reindex API).

body is the request body, e.g. %{source: %{index: "old"}, dest: %{index: "new"}}.

%{source: %{index: "posts-v1"}, dest: %{index: "posts-v2"}}
|> Dowser.Opensearch.Reindex.reindex(params: [wait_for_completion: false])

reindex!(body, opts \\ [])

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

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

reindex_rethrottle(task_id, requests_per_second, opts \\ [])

@spec reindex_rethrottle(id(), number(), keyword()) :: result()

Changes the throttling of the running reindex task task_id (Reindex rethrottle API).

requests_per_second is sent as the required query-string parameter; pass -1 to remove the throttle entirely.

reindex_rethrottle!(task_id, requests_per_second, opts \\ [])

@spec reindex_rethrottle!(id(), number(), keyword()) :: body()

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

update_by_query(body, index, opts \\ [])

@spec update_by_query(map(), index(), keyword()) :: result()

Updates every document matching a query (Update by query API).

body is the request body (e.g. query, script); pass %{} to update everything.

update_by_query!(body, index, opts \\ [])

@spec update_by_query!(map(), index(), keyword()) :: body()

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

update_by_query_rethrottle(task_id, requests_per_second, opts \\ [])

@spec update_by_query_rethrottle(id(), number(), keyword()) :: result()

Changes the throttling of the running update-by-query task task_id (Update by query rethrottle API).

requests_per_second is sent as the required query-string parameter.

update_by_query_rethrottle!(task_id, requests_per_second, opts \\ [])

@spec update_by_query_rethrottle!(id(), number(), keyword()) :: body()

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