An Erlang app for communicating with Elastic Search's rest interface.
Erlang Shell
Latest commit 02b88a9 Dec 13, 2016 @tsloughter committed on GitHub Merge pull request #51 from wk8/wk8/index_exists
Adding `index_exists/*` funs


An Erlang client for Elasticsearch.

Build and Run

$ ./rebar3 shell
==> mimetypes (compile)
==> hackney (compile)
==> jsx (compile)
==> erlastic_search (compile)
exec erl +K true -pa ebin -env ERL_LIBS deps -name erlastic@ -s erlastic_search_app start_deps
Erlang R16B (erts-5.10.1) [source-05f1189] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:true]

Eshell V5.10.1  (abort with ^G)
(erlastic@> erlastic_search:create_index(<<"index_name">>).
{ok, [{<<"ok">>,true},{<<"acknowledged">>,true}]}
(erlastic@> erlastic_search:index_doc(<<"index_name">>, <<"type">>, [{<<"key1">>, <<"value1">>}]).
(erlastic@> erlastic_search:index_doc_with_id(<<"index_name">>, <<"type">>, <<"id1">>, [{<<"key1">>, <<"value1">>}]).
(erlastic@> erlastic_search:search(<<"index_name">>, <<"type">>, <<"key1:value1">>).


First start a local Elasticsearch:

$ bin/elasticsearch

Run Common Test:

$ ./rebar3 ct

Using another JSON library than jsx

By default, we assume all the JSON erlang objects passed to us are in jsx's representation. And similarly, all of Elasticsearch's replies will be decoded with jsx.

However, you might already be using another JSON library in your project, which might encode and decode JSONs from and to a different erlang representation. For example, jiffy:

1> SimpleJson = <<"{\"key\":\"value\"}">>.
2> jiffy:decode(SimpleJson).
3> jsx:decode(SimpleJson).

In that case, you probably want erlastic_search to use your JSON representation of choice instead of jsx's.

You can do so by defining the ERLASTIC_SEARCH_JSON_MODULE environment variable when compiling erlastic_search, for example:

rebar compile

The only constraint is that ERLASTIC_SEARCH_JSON_MODULE should be the name of a module, in your path, that defines the two following callbacks:

-callback encode(erlastic_json()) -> binary().
-callback decode(binary()) -> erlastic_json().

where erlastic_json() is a type mapping to your JSON representation of choice.