2014-07-10 05:20:37 -04:00
|
|
|
== The Ruby Client
|
|
|
|
|
|
|
|
The `elasticsearch` http://rubygems.org/gems/elasticsearch[Rubygem] provides a low-level client
|
|
|
|
for communicating with an Elasticsearch cluster, fully compatible with other official clients.
|
|
|
|
|
2016-03-03 14:03:05 -05:00
|
|
|
Full documentation is hosted at https://github.com/elastic/elasticsearch-ruby[Github]
|
2014-07-10 05:20:37 -04:00
|
|
|
and http://rubydoc.info/gems/elasticsearch[RubyDoc]
|
|
|
|
-- this documentation provides only an overview of features.
|
|
|
|
|
|
|
|
=== Elasticsearch Version Compatibility
|
|
|
|
|
|
|
|
The Ruby API is compatible with both Elasticsearch 0.90.x and 1.0.x versions, you have to install
|
|
|
|
a matching http://rubygems.org/gems/elasticsearch/versions[gem version], though:
|
|
|
|
|
|
|
|
[cols="<,<",options="header",]
|
|
|
|
|=========================================
|
|
|
|
| Elasticsearch version | Ruby gem version
|
|
|
|
| 0.90.x | 0.4.x
|
|
|
|
| 1.x | 1.x
|
|
|
|
|=========================================
|
|
|
|
|
|
|
|
=== Installation
|
|
|
|
|
|
|
|
Install the Ruby gem for Elasticsearch *1.x*:
|
|
|
|
|
|
|
|
[source,sh]
|
|
|
|
------------------------------------
|
|
|
|
gem install elasticsearch
|
|
|
|
------------------------------------
|
|
|
|
|
|
|
|
...or add it do your Gemfile:
|
|
|
|
|
|
|
|
[source,ruby]
|
|
|
|
------------------------------------
|
|
|
|
gem 'elasticsearch'
|
|
|
|
------------------------------------
|
|
|
|
|
|
|
|
Install the Ruby gem for Elasticsearch *0.90.x*:
|
|
|
|
|
|
|
|
[source,sh]
|
|
|
|
------------------------------------
|
|
|
|
gem install elasticsearch -v 0.4.10
|
|
|
|
------------------------------------
|
|
|
|
|
|
|
|
...or add it do your Gemfile:
|
|
|
|
|
|
|
|
[source,ruby]
|
|
|
|
------------------------------------
|
|
|
|
gem 'elasticsearch', '~> 0.4'
|
|
|
|
------------------------------------
|
|
|
|
|
|
|
|
=== Example Usage
|
|
|
|
|
|
|
|
[source,ruby]
|
|
|
|
------------------------------------
|
|
|
|
require 'elasticsearch'
|
|
|
|
|
|
|
|
client = Elasticsearch::Client.new log: true
|
|
|
|
|
|
|
|
client.cluster.health
|
|
|
|
|
|
|
|
client.index index: 'my-index', type: 'my-document', id: 1, body: { title: 'Test' }
|
|
|
|
|
|
|
|
client.indices.refresh index: 'my-index'
|
|
|
|
|
|
|
|
client.search index: 'my-index', body: { query: { match: { title: 'test' } } }
|
|
|
|
------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
=== Features at a Glance
|
|
|
|
|
|
|
|
* Pluggable logging and tracing
|
2015-03-30 17:31:51 -04:00
|
|
|
* Pluggable connection selection strategies (round-robin, random, custom)
|
2014-07-10 05:20:37 -04:00
|
|
|
* Pluggable transport implementation, customizable and extendable
|
|
|
|
* Pluggable serializer implementation
|
|
|
|
* Request retries and dead connections handling
|
|
|
|
* Node reloading (based on cluster state) on errors or on demand
|
|
|
|
* Modular API implementation
|
|
|
|
* 100% REST API coverage
|
|
|
|
|
|
|
|
|
|
|
|
=== Transport and API
|
|
|
|
|
2015-03-09 06:36:17 -04:00
|
|
|
The `elasticsearch` gem combines two separate Rubygems:
|
2014-07-10 05:20:37 -04:00
|
|
|
|
2016-03-03 14:03:05 -05:00
|
|
|
* https://github.com/elastic/elasticsearch-ruby/tree/master/elasticsearch-transport[`elasticsearch-transport`]
|
2018-09-17 15:35:55 -04:00
|
|
|
provides an HTTP Ruby client for connecting to the Elasticsearch cluster,
|
2014-07-10 05:20:37 -04:00
|
|
|
|
2016-03-03 14:03:05 -05:00
|
|
|
* https://github.com/elastic/elasticsearch-ruby/tree/master/elasticsearch-api[`elasticsearch-api`]
|
2014-07-10 05:20:37 -04:00
|
|
|
provides a Ruby API for the Elasticsearch RESTful API.
|
|
|
|
|
|
|
|
Please see their respective documentation for configuration options and technical details.
|
|
|
|
|
|
|
|
Notably, the documentation and comprehensive examples for all the API methods is contained in the source,
|
|
|
|
and available online at http://rubydoc.info/gems/elasticsearch-api/Elasticsearch/API/Actions[Rubydoc].
|
|
|
|
|
2018-09-17 15:35:55 -04:00
|
|
|
Keep in mind, that for optimal performance, you should use an HTTP library which supports
|
2014-07-10 05:20:37 -04:00
|
|
|
persistent ("keep-alive") HTTP connections.
|
|
|
|
|
|
|
|
|
|
|
|
=== Extensions
|
|
|
|
|
2016-03-03 14:03:05 -05:00
|
|
|
The https://github.com/elastic/elasticsearch-ruby/tree/master/elasticsearch-extensions[`elasticsearch-extensions`]
|
2019-01-07 08:44:12 -05:00
|
|
|
Rubygem provides a number of extensions to the core client, such as an API to programmatically launch
|
2014-07-10 05:20:37 -04:00
|
|
|
Elasticsearch clusters (eg. for testing purposes), and more.
|
|
|
|
|
|
|
|
Please see its
|
2016-03-03 14:03:05 -05:00
|
|
|
https://github.com/elastic/elasticsearch-ruby/tree/master/elasticsearch-extensions[documentation]
|
2014-07-10 05:20:37 -04:00
|
|
|
for more information.
|