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 namedquerywhen the body is an Elasticsearch query DSL document, andbody(or a more specific name such asdocumentoroperations) otherwise. :index— optional index target where the endpoint accepts one; endpoints that require an index take it as an argument.HEADexistence checks come as a pair where the?variant plays the bang role:exists/3returns{:ok, boolean()}or{:error, exception},exists?/3returns the bare boolean (404→false) 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.
Deletes the document id
(Delete document API).
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 (404 → false) 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 (404 → false)
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
@type body() :: term()
@type exists_result() :: {:ok, boolean()} | {:error, Exception.t()}
@type id() :: String.t()
@type index() :: Dowser.Elasticsearch.Index.t()
@type result() :: {:ok, body()} | {:error, Exception.t()}
Functions
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.
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).
document is the document body.
Like create/4, but returns the body directly or raises the error exception.
Deletes the document id
(Delete document API).
Like delete/3, but returns the body directly or raises the error exception.
Deletes every document matching a query (Delete by query API).
query is the delete body (query DSL map).
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).
requests_per_second is sent as the required query-string parameter.
Like delete_by_query_rethrottle/3, but returns the body directly or raises
the error exception.
@spec exists(index(), id(), keyword()) :: exists_result()
Checks whether the document id exists
(Document exists API).
Returns {:ok, true}, {:ok, false} or {:error, exception}.
Like exists/3, but returns the boolean directly (404 → false) 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).
document is the document body.
Options
:id— document id; absent to let Elasticsearch generate one.
Like index/3, but returns the body directly or raises the error exception.
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.
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).
body is the request body, e.g. %{docs: [...]} or %{ids: [...]}.
Options
:index— index target; absent when each doc names its own.
Like mtermvectors/2, but returns the body directly or raises the error
exception.
Copies documents from one index to another (Reindex API).
body is the request body, e.g.
%{source: %{index: "old"}, dest: %{index: "new"}}.
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).
requests_per_second is sent as the required query-string parameter.
Like reindex_rethrottle/3, but returns the body directly or raises the
error exception.
@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}.
Like source_exists/3, but returns the boolean directly (404 → false)
or raises the error exception.
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 adocfrom the body.
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).
body is the update body, e.g. %{doc: %{title: "hi"}} or
%{script: %{...}}.
Like update/4, but returns the body directly or raises the error exception.
Updates every document matching a query (Update by query API).
body is the request body (e.g. query, script); pass %{} to update
everything.
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).
requests_per_second is sent as the required query-string parameter.
Like update_by_query_rethrottle/3, but returns the body directly or raises
the error exception.