werbitzky/elastix
{ "createdAt": "2015-07-09T20:50:07Z", "defaultBranch": "master", "description": "A simple Elasticsearch REST client written in Elixir.", "fullName": "werbitzky/elastix", "homepage": "", "language": "Elixir", "name": "elastix", "pushedAt": "2025-02-28T09:39:09Z", "stargazersCount": 254, "topics": [ "elastic", "elasticsearch", "elixir-lang", "index", "json", "rest", "search" ], "updatedAt": "2025-08-27T12:07:34Z", "url": "https://github.com/werbitzky/elastix"}Elastix
Section titled “Elastix”A DSL-free Elasticsearch client for Elixir.
Documentation
Section titled “Documentation”Even though the documentation is pretty scarce right now, we’re working on improving it. If you want to help with that you’re definitely welcome. 🤗
This README contains most of the information you should need to get started, if you can’t find what you’re looking for, either look at the tests or file an issue!
Installation
Section titled “Installation”Add :elastix to your list of dependencies in mix.exs:
def deps do [ {:elastix, ">= 0.0.0"} ]endThen run mix deps.get to fetch the new dependency.
Examples
Section titled “Examples”Creating an Elasticsearch index
Section titled “Creating an Elasticsearch index”Elastix.Index.create("http://localhost:9200", "twitter", %{})Map, Index, Search and Delete
Section titled “Map, Index, Search and Delete”elastic_url = "http://localhost:9200"
data = %{ user: "kimchy", post_date: "2009-11-15T14:12:12", message: "trying out Elastix"}
mapping = %{ properties: %{ user: %{type: "text"}, post_date: %{type: "date"}, message: %{type: "text"} }}
Elastix.Mapping.put(elastic_url, "twitter", "tweet", mapping)Elastix.Document.index(elastic_url, "twitter", "tweet", "42", data)Elastix.Search.search(elastic_url, "twitter", ["tweet"], %{})Elastix.Document.delete(elastic_url, "twitter", "tweet", "42")Bulk requests
Section titled “Bulk requests”Bulk requests take as parameter a list of the lines you want to send to the _bulk endpoint.
You can also specify the following options:
indexthe index of the requesttypethe document type of the request. (you can’t specifytypewithout specifyingindex)httpoison_optionsconfiguration directly passed to httpoison methods. Same options that can be passed on config file
lines = [ %{index: %{_id: "1"}}, %{field: "value1"}, %{index: %{_id: "2"}}, %{field: "value2"}]
Elastix.Bulk.post(elastic_url, lines, index: "my_index", type: "my_type", httpoison_options: [timeout: 180_000])
# You can also send raw data:data = Enum.map(lines, fn line -> Poison.encode!(line) <> "\n" end)Elastix.Bulk.post_raw(elastic_url, data, index: "my_index", type: "my_type")Configuration
Section titled “Configuration”config :elastix, shield: true, username: "username", password: "password",Poison (or any other JSON library) and HTTPoison
Section titled “Poison (or any other JSON library) and HTTPoison”config :elastix, json_options: [keys: :atoms!], httpoison_options: [hackney: [pool: :elastix_pool]]Note that you can configure Elastix to use any JSON library, see the “Custom JSON codec” page for more info.
Custom headers
Section titled “Custom headers”config :elastix, custom_headers: {MyModule, :add_aws_signature, ["us-east"]}custom_headers must be a tuple of the type {Module, :function, [args]}, where :function is a function that should accept the request (a map of this type: %{method: String.t, headers: [], url: String.t, body: String.t}) as its first parameter and return a list of the headers you want to send:
defmodule MyModule do def add_aws_signature(request, region) do [{"Authorization", generate_aws_signature(request, region)} | request.headers] end
defp generate_aws_signature(request, region) do # See: https://github.com/bryanjos/aws_auth or similar endendRunning tests
Section titled “Running tests”You need Elasticsearch running locally on port 9200. A quick way of doing so is via Docker:
$ docker run -p 9200:9200 -it --rm elasticsearch:5.1.2Then clone the repo and fetch its dependencies:
$ git clone git@github.com:werbitzky/elastix.git$ cd elastix$ mix deps.get$ mix test