Snap is an Elasticsearch client. It provides a flexible, performant API on top of your Elasticsearch cluster, supporting high level features like versioned index management, while also providing a convenient interface into low level operations.
See the full API docs.
Disclaimer: Snap is new and may not be production ready yet.
- Versioned index management with zero-downtime hotswapping (compatible with
elasticsearch
) - Streaming bulk operations
- Connection pooling
- Telemetry events
The package can be installed by adding snap
to your list of dependencies in
mix.exs
:
def deps do
[
{:snap, "~> 0.4"}
]
end
Snap supports Elixir 1.9 or later. It might work with earlier versions but is currently untested.
Implement your own cluster module, similar to an Ecto.Repo
:
defmodule MyApp.Cluster do
use Snap.Cluster, otp_app: :my_app
end
Configure it:
config :my_app, MyApp.Cluster,
url: "https://localhost:9200",
username: "my_username",
password: "my_password"
Then wire it into your application supervisor:
def start(_type, _args) do
children = [
{MyApp.Cluster, []}
]
opts = [strategy: :one_for_one, name: MyApp.Supervisor]
Supervisor.start_link(children, opts)
end
Now you can perform operations on your cluster:
{:ok, %{"count" => count}} = MyApp.Cluster.get("/my-index/_count")
See the API documentation for more advanced features.