ProductPromotion
Logo

Elixir

made by https://0x3d.site

GitHub - tsloughter/erlastic_search: An Erlang app for communicating with Elastic Search's rest interface.
An Erlang app for communicating with Elastic Search's rest interface. - tsloughter/erlastic_search
Visit Site

GitHub - tsloughter/erlastic_search: An Erlang app for communicating with Elastic Search's rest interface.

GitHub - tsloughter/erlastic_search: An Erlang app for communicating with Elastic Search's rest interface.

ErlasticSearch

An Erlang client for Elasticsearch.

Build and Run

Start a rebar3 shell

rebar3 shell

Create an index :

erlastic_search:create_index(<<"index_name">>).
{ok, [{<<"ok">>,true},{<<"acknowledged">>,true}]}

Index a document :

erlastic_search:index_doc(<<"index_name">>, <<"type">>, [{<<"key1">>, <<"value1">>}]).
{ok,[{<<"ok">>,true},
     {<<"_index">>,<<"index_name">>},
     {<<"_type">>,<<"type">>},
     {<<"_id">>,<<"T-EzM_yeTkOEHPL9cN5B2g">>},
     {<<"_version">>,1}]}

Index a document (providing a document id) :

erlastic_search:index_doc_with_id(<<"index_name">>, <<"type">>, <<"id1">>, [{<<"key1">>, <<"value1">>}]).
{ok,[{<<"ok">>,true},
     {<<"_index">>,<<"index_name">>},
     {<<"_type">>,<<"type">>},
     {<<"_id">>,<<"id1">>},
     {<<"_version">>,2}]}

Search for a document :

erlastic_search:search(<<"index_name">>, <<"type">>, <<"key1:value1">>).
{ok,[{<<"took">>,6},
     {<<"timed_out">>,false},
     {<<"_shards">>,
      [{<<"total">>,5},{<<"successful">>,5},{<<"failed">>,0}]},
     {<<"hits">>,
      [{<<"total">>,3},
       {<<"max_score">>,0.30685282},
       {<<"hits">>,
        [[{<<"_index">>,<<"index_name">>},
          {<<"_type">>,<<"type">>},
          {<<"_id">>,<<"T-EzM_yeTkOEHPL9cN5B2g">>},
          {<<"_score">>,0.30685282},
          {<<"_source">>,[{<<"key1">>,<<"value1">>}]}],
         [{<<"_index">>,<<"index_name">>},
          {<<"_type">>,<<"type">>},
          {<<"_id">>,<<"id1">>},
          {<<"_score">>,0.30685282},
          {<<"_source">>,[{<<"key1">>,<<"value1">>}]}],
         [{<<"_index">>,<<"index_name">>},
          {<<"_type">>,<<"type">>},
          {<<"_id">>,<<"MMNcfNHUQyeizDkniZD2bg">>},
          {<<"_score">>,0.30685282},
          {<<"_source">>,[{<<"key1">>,<<"value1">>}]}]]}]}]}

Testing

In another terminal use docker-compose to start an Elasticsearch instance :

docker-compose up

For convenience, you can also start a Kibana instance for analysis/visualization :

docker-compose -f docker-compose.yml -f docker-compose-kibana.yml up

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\"}">>.
<<"{\"key\":\"value\"}">>
2> jiffy:decode(SimpleJson).
{[{<<"key">>,<<"value">>}]}
3> jsx:decode(SimpleJson).
[{<<"key">>,<<"value">>}]

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:

export ERLASTIC_SEARCH_JSON_MODULE=jiffy
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.

Articles
to learn more about the elixir concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about Elixir.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory