An API to talk with ElasticSearch without having to learn a new DSL.
You are only required to learn ElasticSearch from its own documentation and then you'll be good to go with Elistix.
Having to learn a whole new DSL for an already known and very well documented service such as ElasticSearch doesn't sound like fun, nor wise.
Well, let's say you learn an entire new DSL and become a wizard when it comes to making use of it, then you jump into a project that relies a different one... and you're pretty much screwed.
Besides, and perhaps even worse, you may be struggling with a query and then you realize that the problem was actually the library. It could be because they don't support that specific feature or library owners have just decided to implement it in a different way from what official documentation says.
Finally, what happens if ElasticSearch version changes? Well, you don't know if the library will work or support the new version... therefore, you'll be limited just to supported versions.
This library is intended to give you total freedom to try/use every aspect of ElasticSearch by simply copying and pasting the code provided by the documentation.
- Add
elistix
to your list of dependencies inmix.exs
:
```elixir
def deps do
[{:elistix, "~> 1.0.1"}]
end
```
- Ensure
elistix
is started before your application:
```elixir
def application do
[applications: [:elistix]]
end
```
The endpoint for Elasticsearch used by default is
"http://127.0.0.1:9200"
To change it you have two choices:
- You can create a
.env
file and add:
```
export ES_URI="URI VALUE"
```
Then, simply run `source .env` in your shell.
- In your Phoenix repository you can set the value in the file
config/{some_env}
e.g.: inconfig/dev.exs
```
config :elistix, :es_uri, "URI VALUE"
```
It just makes use of HTTPoison to make requests to the ElasticSearch service and Poison to deal with JSON.
Before start using Elistix you need to require it
require Elistix
Now you can create a new index and load data at the same time with the following command:
Elistix.Index.load_data("examples", "example", '{"name": "trying elistix", "status": "good"}')
Then you can run a query over the index
query = '{
"query": {
"term": {
"status": {
"value": "good"
}
}
}
}'
Elistix.Query.search("examples", "example", query)
The response has the format provided by HTTPoison:
{ok, response} if everything goes well
{error, reason} if something fail
Even you can build the queries with params given by the endpoint
query = '{
"query": {
"term": {
"status": {
"value": "#{params["status"]}"
}
}
}
}'
Elistix.Query.search("examples", "example", query)