ESClient v0.1.4 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
error()
View Sourceerror() :: ESClient.CodecError.t() | ESClient.RequestError.t() | ESClient.ResponseError.t()
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.
Link to this section Functions
delete(config, location)
View Sourcedelete(ESClient.Config.t(), location()) :: {:ok, ESClient.Response.t()} | {:error, error()}
Dispatch a GET request to the path at the configured endpoint.
delete!(config, location)
View Sourcedelete!(ESClient.Config.t(), location()) :: ESClient.Response.t() | no_return()
Dispatch a GET request to the path at the configured endpoint. Raises when the request fails.
get(config, location)
View Sourceget(ESClient.Config.t(), location()) :: {:ok, ESClient.Response.t()} | {:error, error()}
Dispatch a GET request to the path at the configured endpoint.
get!(config, location)
View Sourceget!(ESClient.Config.t(), location()) :: ESClient.Response.t() | no_return()
Dispatch a GET request to the path at the configured endpoint. Raises when the request fails.
head(config, location)
View Sourcehead(ESClient.Config.t(), location()) :: {:ok, ESClient.Response.t()} | {:error, error()}
Dispatch a HEAD request to the path at the configured endpoint.
head!(config, location)
View Sourcehead!(ESClient.Config.t(), location()) :: ESClient.Response.t() | no_return()
Dispatch a HEAD request to the path at the configured endpoint. Raises when the request fails.
post(config, location, req_data \\ nil)
View Sourcepost(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.
post!(config, location, req_data \\ nil)
View Sourcepost!(ESClient.Config.t(), location(), nil | req_data()) :: ESClient.Response.t() | no_return()
Dispatch a POST request to the path at the configured endpoint using the specified request data. Raises when the request fails.
put(config, location, req_data \\ nil)
View Sourceput(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.
put!(config, location, req_data \\ nil)
View Sourceput!(ESClient.Config.t(), location(), nil | req_data()) :: ESClient.Response.t() | no_return()
Dispatch a PUT request to the path at the configured endpoint using the specified request data. Raises when the request fails.
request(config, verb, location, req_data \\ nil)
View Sourcerequest(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: "..."}}
request!(config, verb, location, req_data \\ nil)
View Sourcerequest!(ESClient.Config.t(), verb(), location(), nil | 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.
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
delete(location)
View Sourcedelete(location()) :: {:ok, ESClient.Response.t()} | {:error, error()}
Dispatch a DELETE request to the path at the configured endpoint.
delete!(location)
View Sourcedelete!(location()) :: ESClient.Response.t() | no_return()
Dispatch a DELETE request to the path at the configured endpoint. Raises when the request fails.
get(location)
View Sourceget(location()) :: {:ok, ESClient.Response.t()} | {:error, error()}
Dispatch a GET request to the path at the configured endpoint.
get!(location)
View Sourceget!(location()) :: ESClient.Response.t() | no_return()
Dispatch a GET request to the path at the configured endpoint. Raises when the request fails.
head(location)
View Sourcehead(location()) :: {:ok, ESClient.Response.t()} | {:error, error()}
Dispatch a HEAD request to the path at the configured endpoint.
head!(location)
View Sourcehead!(location()) :: ESClient.Response.t() | no_return()
Dispatch a HEAD request to the path at the configured endpoint. Raises when the request fails.
post(location)
View Sourcepost(location()) :: {:ok, ESClient.Response.t()} | {:error, error()}
Dispatch a POST request to the path at the configured endpoint.
post(location, req_data)
View Sourcepost(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.
post!(location)
View Sourcepost!(location()) :: ESClient.Response.t() | no_return()
Dispatch a POST request to the path at the configured endpoint. Raises when the request fails.
post!(location, req_data)
View Sourcepost!(location(), req_data()) :: ESClient.Response.t() | no_return()
Dispatch a POST request to the path at the configured endpoint using the specified request data. Raises when the request fails.
put(location)
View Sourceput(location()) :: {:ok, ESClient.Response.t()} | {:error, error()}
Dispatch a PUT request to the path at the configured endpoint.
put(location, req_data)
View Sourceput(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.
put!(location)
View Sourceput!(location()) :: ESClient.Response.t() | no_return()
Dispatch a PUT request to the path at the configured endpoint. Raises when the request fails.
put!(location, req_data)
View Sourceput!(location(), req_data()) :: ESClient.Response.t() | no_return()
Dispatch a PUT request to the path at the configured endpoint using the specified request data. Raises when the request fails.
request(verb, path)
View Sourcerequest(verb(), path()) :: {:ok, ESClient.Response.t()} | {:error, error()}
Dispatch a request to the path at the configured endpoint using the specified request method.
request(verb, path, req_data)
View Sourcerequest(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.
request!(verb, location)
View Sourcerequest!(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.
request!(verb, location, req_data)
View Sourcerequest!(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.