All Projects → breakroom → snap

breakroom / snap

Licence: MIT License
An Elasticsearch client for Elixir

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to snap

appbase-swift
Swift Library for appbase.io and ElasticSearch
Stars: ✭ 24 (-7.69%)
Mutual labels:  elasticsearch-client
gatsby-wiki
Creating a Knowledgbase using Gatsby.js and React.js (see final product ->
Stars: ✭ 32 (+23.08%)
Mutual labels:  elasticsearch-client
VaporElasticsearch
A Vapor/Swift Elasticsearch client
Stars: ✭ 26 (+0%)
Mutual labels:  elasticsearch-client
elasticlient
C++ Elasticsearch client library
Stars: ✭ 112 (+330.77%)
Mutual labels:  elasticsearch-client
wES
wES is set of open source Java ElasticSearch client and toolkits; Compact, yet highly customizable and powerful.
Stars: ✭ 27 (+3.85%)
Mutual labels:  elasticsearch-client
elastic-crud
Simple yet elegant ElasticSearch Crud Repository.
Stars: ✭ 46 (+76.92%)
Mutual labels:  elasticsearch-client
spring-boot-starter-elasticsearchHighLevelClient
提供elasticsearch-rest-high-level-client连接池功能,同时对接spring-boot-starter
Stars: ✭ 57 (+119.23%)
Mutual labels:  elasticsearch-client
Chewy
High-level Elasticsearch Ruby framework based on the official elasticsearch-ruby client
Stars: ✭ 1,749 (+6626.92%)
Mutual labels:  elasticsearch-client
Elasticsearch Hq
Monitoring and Management Web Application for ElasticSearch instances and clusters.
Stars: ✭ 4,832 (+18484.62%)
Mutual labels:  elasticsearch-client
elastic-go
A command-line tool to query the Elasticsearch REST API
Stars: ✭ 17 (-34.62%)
Mutual labels:  elasticsearch-client

Snap

Hex pm

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.

Features

  • Versioned index management with zero-downtime hotswapping (compatible with elasticsearch)
  • Streaming bulk operations
  • Connection pooling
  • Telemetry events

Installation

The package can be installed by adding snap to your list of dependencies in mix.exs:

def deps do
  [
    {:snap, "~> 0.6"},
    {:finch, "~> 0.8"}, # By default, Snap uses Finch to make HTTP requests
  ]
end

Snap supports Elixir 1.11 or later.

Usage

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: "http://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")

Testing

If you want to test your app that uses this library, but don't want to have integration tests with a Elasticsearch instance running in you local dev environment, you can mock the responses using a custom HTTP client adapter.

Supposing you are using mox, you can do something like this:

# in test_helper.exs
Mox.defmock(HTTPClientMock, for: Snap.HTTPClient)
Mox.stub(HTTPClientMock, :child_spec, fn _config -> :skip end)

# in config/test.exs
config :my_app, MyApp.Cluster, http_client_adapter: HTTPClientMock

# in a test file
Mox.expect(HTTPClientMock, :request, fn _cluster, _method, _url, _headers, _body, _opts
  body = "{}" # valid json
  {:ok, %Snap.HTTPClient.Response{status: 200, headers: [], body: body}}
end)

See the API documentation for more advanced features.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].