📜 ⬆️ ⬇️

Elastics: a simple ElasticSearch client for Ruby with everything you need

Year and a half ago I ran into the problem of choosing a client for ElasticSearch for node.js. Then there were several projects, but all were either too complicated, or written anyhow. Although it seemed: all you need is a wrapper around an http request with JSON.encode / decode, error handling and a pair of helper. 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 long been unsupported, others are too complicated. However, many clients do not have an alias management mechanism, although for ES this is a very important functionality.

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. That's what happened.

Minimalist API

ES has good documentation and some methods have many options. In elastics there is no helper for all possible methods. The main method is Client#request , which allows you to execute 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.
DSL for requests either. In my opinion, it only hinders and delays the development (reading documentation, source codes, the need to translate examples of requests from ES documentation to the new DSL).
')
Integration with ActiveRecord

With a choice of index-per-application / index-per-model and CRUD methods. Support other ORM add is not difficult.

Managing indexes and mappings without idle

Elastics stores alias settings in ES, no third-party repositories are required. For a conflicting migration, you can create a new index, start an application that works with it, load data into it, and then update the aliases (there is a task for this). Different indexes are not related to each other: if you need to update the aliases for only one, the rest can be not reindexed.

Rake and Capistrano Taski

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. The code, examples and a more detailed description can be viewed on github .

Source: https://habr.com/ru/post/242897/


All Articles