module Elasticsearch::Model
Elasticsearch
integration for Ruby models
¶ ↑
`Elasticsearch::Model` contains modules for integrating the Elasticsearch
search and analytical engine with ActiveModel-based classes, or models, for the Ruby programming language.
It facilitates importing your data into an index, automatically updating it when a record changes, searching the specific index, setting up the index mapping or the model JSON serialization.
When the `Elasticsearch::Model` module is included in your class, it automatically extends it with the functionality; see {Elasticsearch::Model.included}. Most methods are available via the `__elasticsearch__` class and instance method proxies.
It is possible to include/extend the model with the corresponding modules directly, if that is desired:
MyModel.__send__ :extend, Elasticsearch::Model::Client::ClassMethods MyModel.__send__ :include, Elasticsearch::Model::Client::InstanceMethods MyModel.__send__ :extend, Elasticsearch::Model::Searching::ClassMethods # ...
Constants
- METHODS
- VERSION
Public Class Methods
Adds the `Elasticsearch::Model` functionality to the including class.
-
Creates the `__elasticsearch__` class and instance method. These methods return a proxy object with other common methods defined on them.
-
The module includes other modules with further functionality.
-
Sets up delegation for common methods such as `import` and `search`.
@example Include the module in the `Article` model definition
class Article < ActiveRecord::Base include Elasticsearch::Model end
@example Inject the module into the `Article` model during run time
Article.__send__ :include, Elasticsearch::Model
# File lib/elasticsearch/model.rb, line 108 def self.included(base) base.class_eval do include Elasticsearch::Model::Proxy # Delegate common methods to the `__elasticsearch__` ClassMethodsProxy, unless they are defined already class << self METHODS.each do |method| delegate method, to: :__elasticsearch__ unless self.public_instance_methods.include?(method) end end end # Add to the model to the registry if it's a class (and not in intermediate module) Registry.add(base) if base.is_a?(Class) end