A DSL-free Elasticsearch client for Elixir.
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!
Add elastix
to your list of dependencies in mix.exs
:
def deps do
[{:elastix, ">= 0.0.0"}]
end
Then run mix deps.get
to fetch the new dependency.
Elastix.Index.create("https://localhost:9200", "twitter", %{})
elastic_url = "https://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 take as parameter a list of the lines you want to send to the _bulk
endpoint.
You can also specify the following options:
index
the index of the requesttype
the document type of the request. (you can't specifytype
without specifyingindex
)httpoison_options
configuration 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")
config :elastix,
shield: true,
username: "username",
password: "password",