Elasticsearch gems and modules, clearly explained

written by Maxim Chernyak on 15 Sep, 15

Non Rails-specific

Gem elasticsearch-transport

Provides a bare-bones HTTP client that doesn’t have any Elasticsearch-specific api methods, but knows how to discover and connect to multiple servers, rotate connections, and log things.

Gem elasticsearch-api

Provides a module that adds elasticsearch-specific methods such as search, cluster, index to a generic HTTP client. Can be included in any class that implements method perform_request which returns an object responding to status, body, headers.

Gem elasticsearch

Depends on:

All it does is it takes an HTTP client from elasticsearch-transport and includes the Elasticsearch::API module into it from elasticsearch-api, providing a more convenient client as a result.

Gem elasticsearch-dsl

Provides a tire-like syntax for defining queries. The resulting query object is useless on its own, but it supports to_hash, and therefore can easily be fed into any HTTP client by encoding Hash as JSON. If you feed this object to the client from elasticsearch-transport, it will be automatically dumped as JSON using the default MultiJson serializer.

Gem elasticsearch-watcher

Depends on:

Extends Elasticsearch::API with an extra method watcher, which in turn provides methods specific for the Watcher plugin, such as put_watch, get_watch, and others.

Gem elasticsearch-extensions

Depends on:

Adds contributor-friendly features like terminal colorizers and formatters for Elasticsearch responses, cluster start/stop for testing, and profiling features for testing.


Gem elasticsearch-model

Depends on:

This gem contains various modules to be included into models. It does nothing without explicit includes.

Module Elasticsearch::Model::Proxy

This module is useless on its own. It adds __elasticsearch__ method to a model at class and instance levels, which is supposed to isolate all elasticsearch functionality underneath it. However, the proxy object is actually empty, it has no methods, and it expects that all other modules will be manually included into it.

Module Elasticsearch::Model::Client

Adds accessor client to the model at both class and instance level. Default client comes from elasticsearch-transport.

Module Elasticsearch::Model::Naming

Adds accessors index_name and document_type to the model at both class and instance level. Defaults are inferred from the model name.

Module Elasticsearch::Model::Indexing

Adds class methods settings, mapping, create_index!, index_exists?, delete_index!, and refresh_index! which can be used to define and manage field mappings. Index methods would implicitly use the previously defined mapping, as well as implicitly inferred index/document_type names. The module also adds instance methods index_document, update_document, and delete_document that depend on model having as_indexed_json, and id to work.

Module Elasticsearch::Model::Searching

Adds class level search method that accepts a to_hash-compatible object, delegates to the search method on the client. By default the client is coming from elasticsearch-transport.

Module Elasticsearch::Model::Serializing

Adds an instance method as_indexed_json to a model, which by default delegates to as_json with option root: false.

module source/docs: elasticsearch-rails/elasticsearch-model/lib/elasticsearch/model/serializing.rb

Module Elasticsearch::Model::Importing

Provides class-level method import allowing batches of records to be efficiently imported into Elasticsearch. This module automatically adapts for ActiveRecord and Mongoid.

module source/docs: elasticsearch-rails/elasticsearch-model/lib/elasticsearch/model/importing.rb

Module Elasticsearch::Model

When included, this module does 3 things.

  1. Includes Elasticsearch::Model::Proxy into the model.
  2. Includes the following modules into the __elasticsearch__ proxy object. * Elasticsearch::Model::Client * Elasticsearch::Model::Naming * Elasticsearch::Model::Indexing * Elasticsearch::Model::Searching * Elasticsearch::Model::Serializing * Elasticsearch::Model::Importing
  3. Delegates some important methods from model class/instance to the __elasticsearch__ proxy object, namely search, mapping, settings, index_name, document_type, import.

module source/docs: elasticsearch-rails/elasticsearch-model/lib/elasticsearch/model.rb

Module Elasticsearch::Model::Callbacks

Adds callbacks that sync model and Elasticsearch representation on create/update/delete. The callbacks are blocking, if the syncing must be asynchronous it’s suggested to implement your own callbacks, and not use this module. This module automatically adapts for ActiveRecord and Mongoid.

module source/docs: elasticsearch-rails/elasticsearch-model/lib/elasticsearch/model/callbacks.rb

Gem elasticsearch-persistence

Depends on:

Provides a way to build models backed by Elasticsearch database, similar to ActiveRecord models being backed by SQL database. Additionally, provides a way of using Repository pattern to the same effect.

Gem elasticsearch-rails

Provides rake tasks for importing data from Rails models into Elasticsearch, as well as instrumentation for displaying search requests and their stats in logs. Includes special support for Lograge. Both rake tasks and instrumentation features must be manually required to function (no railtie support). Comes with multiple Rails application templates which allow the user to generate example applications locally, starting from a very simple integration, to a full-blown Elasticsearc-powered application, to demonstrate the gem capabilities and common usage patterns.

comments powered by Disqus