Coder Social home page Coder Social logo

qualia91 / elasticsearch-erlang Goto Github PK

View Code? Open in Web Editor NEW

This project forked from snorecone/elasticsearch-erlang

0.0 0.0 1.0 169 KB

An erlang client for elasticsearch's REST interface with built-in connection pooling.

License: Apache License 2.0

Erlang 97.70% Makefile 2.30%

elasticsearch-erlang's Introduction

elasticsearch-erlang

An erlang client for elasticsearch's REST interface. Just the bare minimum for now.



Other elasticsearch clients and why this was made

  • erlasticsearch - too much frustration with thrift.
  • erlastic_search - dependency on hackney for http requests (built-in pooling is broken); unable to configure without wrapping the module.

Config

Default config is shown below. You can supply your own config in sys.config, but must be of this form.

{elasticsearch, [
    {pools, [
        {elasticsearch_workers, [
            {size,         10},
            {max_overflow, 20}
        ], [
            {worker_impl,  elasticsearch_worker},
            {url,          "localhost"},
            {port,         9200},
            {http_options, []}
        ]}
    ]}
]},
  • worker_impl: This is the default worker, but you can supply your own. Must conform to poolboy worker behaviour specs.

Usage

Create index:

elasticsearch:create_index(<<"my_index">>).

Add to index using jsx to convert map:

elasticsearch:index(<<"my_index">>, <<"_doc">>, #{<<"my_key">> => <<"my_value">>}).

Add to index using binary query:

elasticsearch:index(<<"my_index">>, <<"_doc">>, <<"{\"my_key\": \"my_value\"}">>).

Add to index with id:

elasticsearch:index(<<"my_index">>, <<"_doc">>, <<"id">>, #{<<"my_key">> => <<"my_value">>}).

Get document:

elasticsearch:get_document(<<"my_index">>, <<"_doc">>, <<"id">>).

Add in bulk using jsx to convert map:

elasticsearch:index(<<"bank">>, <<"_bulk">>, [#{ <<"index">> => #{<<"_index">> => <<"abc">>} }, #{<<"my_key5">> => <<"my_value5">>}, #{ <<"index">> => #{<<"_index">> => <<"abc">>} }, #{<<"my_key6">> => <<"my_value6">>}, #{ <<"index">> => #{<<"_index">> => <<"abc">>} }, #{<<"my_key7">> => <<"my_value7">>}]).

Add in bulk using binary query:

elasticsearch:index(<<"bank">>, <<"_bulk">>, <<"{ \"index\": {\"_index\": \"abc\"} }\n{\"my_key5\": \"my_value5\"}\n{ \"index\": {\"_index\": \"abc\"} }\n{\"my_key6\": \"my_value6\"}\n{ \"index\": {\"_index\": \"abc\"} }\n{\"my_key7\": \"my_value7\"}\n">>).

Search:

elasticsearch:search(<<"my_index">>, <<"_doc">>, #{<<"query">> => #{<<"match">> => #{<<"key1">> => <<"value1">>}}}).

Count:

elasticsearch:count(<<"my_index">>, <<"_doc">>, #{<<"query">> => #{<<"match">> => #{<<"key1">> => <<"value1">>}}}).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.