ESClient v0.1.3 ESClient behaviour View Source

A minimalistic Elasticsearch client for Elixir.

Usage

You can call the client directly if you have a config struct.

iex> config = %ESClient.Config{base_url: "http://localhost:9201"}
...> ESClient.get!(config, "_cat/health")
#ESClient.Response<...>

It's also possible to pass a list of path segments.

ESClient.get!(config, ["_cat", "health"])

When the location is a tuple, the second element becomes encoded as query params.

ESClient.get!(config, {["_cat", "health"], verbose: true})

Alternatively, you can use this module to build your own custom client and obtain values from the application config.

defmodule MyCustomClient
  use ESClient, otp_app: :my_app
end

Don't forget to add the configuration to your config.exs.

use Mix.Config
# or
import Config

config :my_app, MyCustomClient,
  base_url: "http://localhost:9201",
  json_keys: :atoms,
  json_library: Jason,
  timeout: 15_000

Then, use your client.

iex> MyCustomClient.get!("_cat/health")
#ESClient.Response<...>

Link to this section Summary

Types

Type defining an error that be be returned or raised when sending a request to a resource.

A type that defines a location on the remote server, allowing optional query parameters.

A type that defines a String containing path segments separated by slashes or a list of path segments.

A type that defines a list of path segments.

A type that defines a String containing path segments separated by slashes.

A type that defines request data.

A type that refers to a HTTP method to perform the request with.

Functions

Dispatch a GET request to the path at the configured endpoint.

Dispatch a GET request to the path at the configured endpoint. Raises when the request fails.

Dispatch a GET request to the path at the configured endpoint.

Dispatch a GET request to the path at the configured endpoint. Raises when the request fails.

Dispatch a HEAD request to the path at the configured endpoint.

Dispatch a HEAD request to the path at the configured endpoint. Raises when the request fails.

Dispatch a POST request to the path at the configured endpoint using the specified request data.

Dispatch a POST request to the path at the configured endpoint using the specified request data. Raises when the request fails.

Dispatch a PUT request to the path at the configured endpoint using the specified request data.

Dispatch a PUT request to the path at the configured endpoint using the specified request data. Raises when the request fails.

Sends a request with the given verb to the configured endpoint.

Dispatch a request to the path at the configured endpoint using the specified request method and data. Raises when the request fails.

Callbacks

Dispatch a DELETE request to the path at the configured endpoint.

Dispatch a DELETE request to the path at the configured endpoint. Raises when the request fails.

Dispatch a GET request to the path at the configured endpoint.

Dispatch a GET request to the path at the configured endpoint. Raises when the request fails.

Dispatch a HEAD request to the path at the configured endpoint.

Dispatch a HEAD request to the path at the configured endpoint. Raises when the request fails.

Dispatch a POST request to the path at the configured endpoint.

Dispatch a POST request to the path at the configured endpoint using the specified request data.

Dispatch a POST request to the path at the configured endpoint. Raises when the request fails.

Dispatch a POST request to the path at the configured endpoint using the specified request data. Raises when the request fails.

Dispatch a PUT request to the path at the configured endpoint.

Dispatch a PUT request to the path at the configured endpoint using the specified request data.

Dispatch a PUT request to the path at the configured endpoint. Raises when the request fails.

Dispatch a PUT request to the path at the configured endpoint using the specified request data. Raises when the request fails.

Dispatch a request to the path at the configured endpoint using the specified request method.

Dispatch a request to the path at the configured endpoint using the specified request method and data.

Dispatch a request to the path at the configured endpoint using the specified request method. Raises when the request fails.

Dispatch a request to the path at the configured endpoint using the specified request method and data. Raises when the request fails.

Link to this section Types

Type defining an error that be be returned or raised when sending a request to a resource.

Link to this type

location()

View Source
location() :: path() | {path(), query :: Enum.t()}

A type that defines a location on the remote server, allowing optional query parameters.

A type that defines a String containing path segments separated by slashes or a list of path segments.

Link to this type

path_segments()

View Source
path_segments() :: [String.t()]

A type that defines a list of path segments.

Link to this type

path_str()

View Source
path_str() :: String.t()

A type that defines a String containing path segments separated by slashes.

Link to this type

req_data()

View Source
req_data() ::
  String.t() | Keyword.t() | %{optional(atom() | String.t()) => any()}

A type that defines request data.

Link to this type

verb()

View Source
verb() :: :head | :get | :post | :put | :delete

A type that refers to a HTTP method to perform the request with.

Link to this section Functions

Link to this function

delete(config, location)

View Source
delete(ESClient.Config.t(), location()) ::
  {:ok, ESClient.Response.t()} | {:error, error()}

Dispatch a GET request to the path at the configured endpoint.

Dispatch a GET request to the path at the configured endpoint. Raises when the request fails.

Link to this function

get(config, location)

View Source
get(ESClient.Config.t(), location()) ::
  {:ok, ESClient.Response.t()} | {:error, error()}

Dispatch a GET request to the path at the configured endpoint.

Dispatch a GET request to the path at the configured endpoint. Raises when the request fails.

Link to this function

head(config, location)

View Source
head(ESClient.Config.t(), location()) ::
  {:ok, ESClient.Response.t()} | {:error, error()}

Dispatch a HEAD request to the path at the configured endpoint.

Dispatch a HEAD request to the path at the configured endpoint. Raises when the request fails.

Link to this function

post(config, location, req_data \\ nil)

View Source
post(ESClient.Config.t(), location(), nil | req_data()) ::
  {:ok, ESClient.Response.t()} | {:error, error()}

Dispatch a POST request to the path at the configured endpoint using the specified request data.

Link to this function

post!(config, location, req_data \\ nil)

View Source

Dispatch a POST request to the path at the configured endpoint using the specified request data. Raises when the request fails.

Link to this function

put(config, location, req_data \\ nil)

View Source
put(ESClient.Config.t(), location(), nil | req_data()) ::
  {:ok, ESClient.Response.t()} | {:error, error()}

Dispatch a PUT request to the path at the configured endpoint using the specified request data.

Link to this function

put!(config, location, req_data \\ nil)

View Source

Dispatch a PUT request to the path at the configured endpoint using the specified request data. Raises when the request fails.

Link to this function

request(config, verb, location, req_data \\ nil)

View Source
request(config :: ESClient.Config.t(), verb(), location(), nil | req_data()) ::
  {:ok, ESClient.Response.t()} | {:error, error()}

Sends a request with the given verb to the configured endpoint.

Examples

iex> ESClient.request(config, :get, "_cat/health")
{:ok, %ESClient.Response{body: "..."}}

iex> ESClient.request(config, :get, ["_cat", "health"])
{:ok, %ESClient.Response{body: "..."}}

iex> ESClient.request(config, :get, {["_cat", "invalid"], foo: "bar"})
{:error, %ESClient.ResponseError{reason: "..."}}

iex> ESClient.request(config, :put, "my-index", %{settings: %{...}})
{:ok, %ESClient.Response{body: "..."}}
Link to this function

request!(config, verb, location, req_data \\ nil)

View Source

Dispatch a request to the path at the configured endpoint using the specified request method and data. Raises when the request fails.

Examples

iex> ESClient.request!(config, :get, "_cat/health")
%ESClient.Response{body: "..."}

iex> ESClient.request!(config, :get, ["_cat", "health"])
%ESClient.Response{body: "..."}

iex> ESClient.request!(config, :get, {["_cat", "invalid"], foo: "bar"})
** (ESClient.ResponseError) ...

iex> ESClient.request!(config, :put, "my-index", %{settings: %{...}})
%ESClient.Response{body: "..."}

Link to this section Callbacks

Link to this callback

delete(location)

View Source
delete(location()) :: {:ok, ESClient.Response.t()} | {:error, error()}

Dispatch a DELETE request to the path at the configured endpoint.

Dispatch a DELETE request to the path at the configured endpoint. Raises when the request fails.

Link to this callback

get(location)

View Source
get(location()) :: {:ok, ESClient.Response.t()} | {:error, error()}

Dispatch a GET request to the path at the configured endpoint.

Dispatch a GET request to the path at the configured endpoint. Raises when the request fails.

Link to this callback

head(location)

View Source
head(location()) :: {:ok, ESClient.Response.t()} | {:error, error()}

Dispatch a HEAD request to the path at the configured endpoint.

Dispatch a HEAD request to the path at the configured endpoint. Raises when the request fails.

Link to this callback

post(location)

View Source
post(location()) :: {:ok, ESClient.Response.t()} | {:error, error()}

Dispatch a POST request to the path at the configured endpoint.

Link to this callback

post(location, req_data)

View Source
post(location(), req_data()) :: {:ok, ESClient.Response.t()} | {:error, error()}

Dispatch a POST request to the path at the configured endpoint using the specified request data.

Dispatch a POST request to the path at the configured endpoint. Raises when the request fails.

Dispatch a POST request to the path at the configured endpoint using the specified request data. Raises when the request fails.

Link to this callback

put(location)

View Source
put(location()) :: {:ok, ESClient.Response.t()} | {:error, error()}

Dispatch a PUT request to the path at the configured endpoint.

Link to this callback

put(location, req_data)

View Source
put(location(), req_data()) :: {:ok, ESClient.Response.t()} | {:error, error()}

Dispatch a PUT request to the path at the configured endpoint using the specified request data.

Dispatch a PUT request to the path at the configured endpoint. Raises when the request fails.

Dispatch a PUT request to the path at the configured endpoint using the specified request data. Raises when the request fails.

Link to this callback

request(verb, path)

View Source
request(verb(), path()) :: {:ok, ESClient.Response.t()} | {:error, error()}

Dispatch a request to the path at the configured endpoint using the specified request method.

Link to this callback

request(verb, path, req_data)

View Source
request(verb(), path(), req_data()) ::
  {:ok, ESClient.Response.t()} | {:error, error()}

Dispatch a request to the path at the configured endpoint using the specified request method and data.

Link to this callback

request!(verb, location)

View Source
request!(verb(), location()) :: ESClient.Response.t() | no_return()

Dispatch a request to the path at the configured endpoint using the specified request method. Raises when the request fails.

Link to this callback

request!(verb, location, req_data)

View Source
request!(verb(), location(), req_data()) :: ESClient.Response.t() | no_return()

Dispatch a request to the path at the configured endpoint using the specified request method and data. Raises when the request fails.