Dowser.Elasticsearch.Document (Dowser.Elasticsearch v0.1.0)

View Source

The Elasticsearch document APIs — every endpoint tagged document in the Elasticsearch OpenAPI specification (single-document CRUD, bulk, multi-get, by-query operations, reindex, term vectors).

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

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 Elasticsearch query DSL document, and body (or a more specific name such as document or operations) otherwise.
  • :index — optional index target where the endpoint accepts one; endpoints that require an index take it as an argument.
  • HEAD existence checks come as a pair where the ? variant plays the bang role: exists/3 returns {:ok, boolean()} or {:error, exception}, exists?/3 returns the bare boolean (404false) and raises on genuine errors.

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

Values are cast automatically wherever :codec_adapter is set to Dowser.Elasticsearch.TypeCodec — no per-call option needed.

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. Each function has a bang variant that returns the body directly or raises the error exception.

Summary

Functions

Performs several index/create/update/delete operations in one request (Bulk API).

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

Creates the document id, failing if it already exists (Create document API).

Like create/4, but returns the body directly or raises the error exception.

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

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.

Checks whether the document id exists (Document exists API).

Like exists/3, but returns the boolean directly (404false) or raises the error exception.

Retrieves the document id (Get document API).

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

Retrieves the source of the document id, without metadata (Get document source API).

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

Indexes (creates or replaces) a document (Index document API).

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

Retrieves several documents in one request (Multi get API).

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

Returns term vectors for several documents in one request (Multi term vectors API).

Like mtermvectors/2, 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.

Checks whether the document id exists and has a source (Source exists API).

Like source_exists/3, but returns the boolean directly (404false) or raises the error exception.

Returns term and field statistics for a stored or artificial document (Term vectors API).

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

Updates the document id with a script or a partial document (Update document API).

Like update/4, 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()

exists_result()

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

id()

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

index()

@type index() :: Dowser.Elasticsearch.Index.t()

result()

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

Functions

bulk(operations, opts \\ [])

@spec bulk(
  [map()],
  keyword()
) :: result()

Performs several index/create/update/delete operations in one request (Bulk API).

operations is a flat list alternating action and payload maps, encoded as NDJSON:

Dowser.Elasticsearch.Document.bulk([
  %{index: %{_id: "1"}},
  %{title: "hello"},
  %{delete: %{_id: "2"}}
])

Options

  • :index — default index target for actions that name none.

bulk!(operations, opts \\ [])

@spec bulk!(
  [map()],
  keyword()
) :: body()

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

create(document, index, id, opts \\ [])

@spec create(map(), index(), id(), keyword()) :: result()

Creates the document id, failing if it already exists (Create document API).

document is the document body.

create!(document, index, id, opts \\ [])

@spec create!(map(), index(), id(), keyword()) :: body()

Like create/4, but returns the body directly or raises the error exception.

delete(index, id, opts \\ [])

@spec delete(index(), id(), keyword()) :: result()

Deletes the document id (Delete document API).

delete!(index, id, opts \\ [])

@spec delete!(index(), id(), keyword()) :: body()

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

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.

exists(index, id, opts \\ [])

@spec exists(index(), id(), keyword()) :: exists_result()

Checks whether the document id exists (Document exists API).

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

exists?(index, id, opts \\ [])

@spec exists?(index(), id(), keyword()) :: boolean()

Like exists/3, but returns the boolean directly (404false) or raises the error exception.

get(index, id, opts \\ [])

@spec get(index(), id(), keyword()) :: result()

Retrieves the document id (Get document API).

get!(index, id, opts \\ [])

@spec get!(index(), id(), keyword()) :: body()

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

get_source(index, id, opts \\ [])

@spec get_source(index(), id(), keyword()) :: result()

Retrieves the source of the document id, without metadata (Get document source API).

get_source!(index, id, opts \\ [])

@spec get_source!(index(), id(), keyword()) :: body()

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

index(document, index, opts \\ [])

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

Indexes (creates or replaces) a document (Index document API).

document is the document body.

Options

  • :id — document id; absent to let Elasticsearch generate one.

index!(document, index, opts \\ [])

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

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

mget(body, opts \\ [])

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

Retrieves several documents in one request (Multi get API).

body is the request body, e.g. %{ids: ["1", "2"]} or %{docs: [...]}.

Options

  • :index — index target; absent when each doc names its own.

mget!(body, opts \\ [])

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

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

mtermvectors(body, opts \\ [])

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

Returns term vectors for several documents in one request (Multi term vectors API).

body is the request body, e.g. %{docs: [...]} or %{ids: [...]}.

Options

  • :index — index target; absent when each doc names its own.

mtermvectors!(body, opts \\ [])

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

Like mtermvectors/2, 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"}}.

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.

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.

source_exists(index, id, opts \\ [])

@spec source_exists(index(), id(), keyword()) :: exists_result()

Checks whether the document id exists and has a source (Source exists API).

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

source_exists?(index, id, opts \\ [])

@spec source_exists?(index(), id(), keyword()) :: boolean()

Like source_exists/3, but returns the boolean directly (404false) or raises the error exception.

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

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

Returns term and field statistics for a stored or artificial document (Term vectors API).

body is the request body (e.g. doc, fields, filter); pass %{} to send nothing.

Options

  • :id — stored document id; absent when analyzing a doc from the body.

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

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

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

update(body, index, id, opts \\ [])

@spec update(map(), index(), id(), keyword()) :: result()

Updates the document id with a script or a partial document (Update document API).

body is the update body, e.g. %{doc: %{title: "hi"}} or %{script: %{...}}.

update!(body, index, id, opts \\ [])

@spec update!(map(), index(), id(), keyword()) :: body()

Like update/4, 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.