The `elasticsearch-persistence` http://rubygems.org/gems/elasticsearch-persistence[Rubygem]
provides persistence layer for Ruby domain objects.
It supports two design patterns for integrating with your objects: _repository_ and _active record_.
=== Repository
The `Elasticsearch::Persistence::Repository` module provides an implementation of the repository pattern and allows to save, delete, find and search objects stored in Elasticsearch, as well as configure mappings and settings for the index.
==== Features At a Glance
* Access to the Elasticsearch client
* Setting the index name, document type, and object class for deserialization
* Composing mappings and settings for the index
* Creating, deleting or refreshing the index
* Finding or searching for documents
* Providing access both to domain objects and hits for search results
* Providing access to the Elasticsearch response for search results (aggregations, total, ...)
* Defining the methods for serialization and deserialization
==== Usage
Let's have a simple plain old Ruby object (PORO):
[source,ruby]
------------------------------------
class Note
attr_reader :attributes
def initialize(attributes={})
@attributes = attributes
end
def to_hash
@attributes
end
end
------------------------------------
Let's create a default, "dumb" repository, as a first step:
https://github.com/elasticsearch/elasticsearch-rails/tree/master/elasticsearch-persistence#example-application[example application] which demonstrates the usage patterns of the _repository_ approach to persistence.
=== Active Record
The `Elasticsearch::Persistence::Model` module provides an implementation of the active record pattern, with
a familiar interface for using Elasticsearch as a persistence layer in Ruby on Rails applications. The model
is fully compatible with Rails' conventions and helpers, such as `url_for`.
All the methods are documented with comprehensive examples in the source code, available also
https://github.com/elasticsearch/elasticsearch-rails/tree/master/elasticsearch-persistence#example-application-1[example application] which demonstrates the usage patterns of the _active record_ approach to persistence.