README.md in elasticsearch-model-0.1.9 vs README.md in elasticsearch-model-2.0.0
- old
+ new
@@ -1,29 +1,41 @@
# Elasticsearch::Model
The `elasticsearch-model` library builds on top of the
-the [`elasticsearch`](https://github.com/elasticsearch/elasticsearch-ruby) library.
+the [`elasticsearch`](https://github.com/elastic/elasticsearch-ruby) library.
It aims to simplify integration of Ruby classes ("models"), commonly found
e.g. in [Ruby on Rails](http://rubyonrails.org) applications, with the
[Elasticsearch](http://www.elasticsearch.org) search and analytics engine.
-The library is compatible with Ruby 1.9.3 and higher.
+## Compatibility
+This library is compatible with Ruby 1.9.3 and higher.
+
+The library version numbers follow the Elasticsearch major versions, and the `master` branch
+is compatible with the Elasticsearch `master` branch, therefore, with the next major version.
+
+| Rubygem | | Elasticsearch |
+|:-------------:|:-:| :-----------: |
+| 0.1 | → | 1.x |
+| 2.x | → | 2.x |
+| 5.x | → | 5.x |
+| master | → | master |
+
## Installation
Install the package from [Rubygems](https://rubygems.org):
gem install elasticsearch-model
To use an unreleased version, either add it to your `Gemfile` for [Bundler](http://bundler.io):
- gem 'elasticsearch-model', git: 'git://github.com/elasticsearch/elasticsearch-rails.git'
+ gem 'elasticsearch-model', git: 'git://github.com/elastic/elasticsearch-rails.git', branch: '5.x'
or install it from a source code checkout:
- git clone https://github.com/elasticsearch/elasticsearch-rails.git
+ git clone https://github.com/elastic/elasticsearch-rails.git
cd elasticsearch-rails/elasticsearch-model
bundle install
rake install
@@ -107,11 +119,11 @@
See the `Elasticsearch::Model` module documentation for technical information.
### The Elasticsearch client
-The module will set up a [client](https://github.com/elasticsearch/elasticsearch-ruby/tree/master/elasticsearch),
+The module will set up a [client](https://github.com/elastic/elasticsearch-ruby/tree/master/elasticsearch),
connected to `localhost:9200`, by default. You can access and use it as any other `Elasticsearch::Client`:
```ruby
Article.__elasticsearch__.client.cluster.health
# => { "cluster_name"=>"elasticsearch", "status"=>"yellow", ... }
@@ -130,11 +142,11 @@
```
You might want to do this during your application bootstrap process, e.g. in a Rails initializer.
Please refer to the
-[`elasticsearch-transport`](https://github.com/elasticsearch/elasticsearch-ruby/tree/master/elasticsearch-transport)
+[`elasticsearch-transport`](https://github.com/elastic/elasticsearch-ruby/tree/master/elasticsearch-transport)
library documentation for all the configuration options, and to the
[`elasticsearch-api`](http://rubydoc.info/gems/elasticsearch-api) library documentation
for information about the Ruby client API.
### Importing the data
@@ -239,11 +251,11 @@
```
The `records` method returns the real instances of your model, which is useful when you want to access your
model methods -- at the expense of slowing down your application, of course.
In most cases, working with `results` coming from Elasticsearch is sufficient, and much faster. See the
-[`elasticsearch-rails`](https://github.com/elasticsearch/elasticsearch-rails/tree/master/elasticsearch-rails)
+[`elasticsearch-rails`](https://github.com/elastic/elasticsearch-rails/tree/master/elasticsearch-rails)
library for more information about compatibility with the Ruby on Rails framework.
When you want to access both the database `records` and search `results`, use the `each_with_hit`
(or `map_with_hit`) iterator:
@@ -301,11 +313,11 @@
# => 3
```
To initialize and include the Kaminari pagination support manually:
```ruby
-Kaminari::Hooks.init
+Kaminari::Hooks.init if defined?(Kaminari::Hooks)
Elasticsearch::Model::Response::Response.__send__ :include, Elasticsearch::Model::Response::Pagination::Kaminari
```
#### The Elasticsearch DSL
@@ -318,12 +330,12 @@
response.results.first.highlight.title
# ["Quick brown <em>fox</em>"]
```
-You can pass any object which implements a `to_hash` method, or you can use your favourite JSON builder
-to build the search definition as a JSON string:
+You can pass any object which implements a `to_hash` method, which is called automatically,
+so you can use a custom class or your favourite JSON builder to build the search definition:
```ruby
require 'jbuilder'
query = Jbuilder.encode do |json|
@@ -339,10 +351,29 @@
response = Article.search query
response.results.first.title
# => "Quick brown fox"
```
+Also, you can use the [**`elasticsearch-dsl`**](https://github.com/elastic/elasticsearch-ruby/tree/master/elasticsearch-dsl) library, which provides a specialized Ruby API for
+the Elasticsearch Query DSL:
+
+```ruby
+require 'elasticsearch/dsl'
+
+query = Elasticsearch::DSL::Search.search do
+ query do
+ match :title do
+ query 'fox dogs'
+ end
+ end
+end
+
+response = Article.search query
+response.results.first.title
+# => "Quick brown fox"
+```
+
### Index Configuration
For proper search engine function, it's often necessary to configure the index properly.
The `Elasticsearch::Model` integration provides class methods to set up index settings and mappings.
@@ -682,9 +713,21 @@
# => DataMapper::Collection
```
More examples can be found in the `examples` folder. Please see the `Elasticsearch::Model::Adapter`
module and its submodules for technical information.
+
+### Settings
+
+The module provides a common `settings` method to customize various features.
+
+At the moment, the only supported setting is `:inheritance_enabled`, which makes the class receiving the module
+respect index names and document types of a super-class, eg. in case you're using "single table inheritance" (STI)
+in Rails:
+
+```ruby
+Elasticsearch::Model.settings[:inheritance_enabled] = true
+```
## Development and Community
For local development, clone the repository and run `bundle install`. See `rake -T` for a list of
available Rake tasks for running tests, generating documentation, starting a testing cluster, etc.