Elastics: A Simple ElasticSearch Client for Ruby with Everything You Need

    A year and a half ago, I encountered the problem of choosing a client for ElasticSearch for node.js. Then there were several projects, but all were either too complicated, or they were written anyhow. Although it seemed: all that is needed is a wrapper around the http request with JSON.encode / decode, error handling and a couple of helpers. Then for the node, I quickly wrote a small module , which turned out to be very convenient.

    Recently it was necessary to fasten the ES to the application on the rails. Some clients for Ruby have not been supported for a long time, while others are too complicated. However, many clients do not have an alias management mechanism, although this is a very important feature for ES.

    I decided to write a minimalistic gem, taking as a basis the module for node.js and expanding its functionality so that there are all the most necessary tools for development, deployment and management. Here's what happened.

    Minimalistic API

    ES has good documentation and some methods have many settings. Elastics has no helper for all possible methods. The main method is Client#requestto allow you to perform any request. There are helpers for http methods and some simple requests. With this approach, there will never be a situation that elastics does not support the functions of new / old versions.
    There is no DSL for queries either. In my opinion, it only interferes and delays development (reading documentation, source codes, the need to translate sample requests from ES documentation to the new DSL).

    ActiveRecord Integration

    With the ability to select index-per-application / index-per-model and CRUD methods. Support for other ORMs is easy to add.

    Manage indexes and mappings without downtime

    Elastics stores alias settings in ES; no third-party storage is required. For conflicting migration, you can create a new index, run the application that works with it, load data into it, and then update the aliases (there is a task for this). Different indexes are in no way interconnected: if you need to update aliases for only one, the rest can be re-indexed.

    Rake and Capistrano Tusky

    for migrations and indexing models.

    AutoRefresh mode for testing

    In this mode, after each request that changes state, a refresh request is executed at the same index.

    Elastics works with and without rails. Code, examples and a more detailed description can be found on github .

    Also popular now: