"Fossies" - the Fresh Open Source Software Archive

Member "elasticsearch-6.8.23/docs/ruby/client.asciidoc" (29 Dec 2021, 3600 Bytes) of package /linux/www/elasticsearch-6.8.23-src.tar.gz:

As a special service "Fossies" has tried to format the requested source page into HTML format (assuming AsciiDoc format). Alternatively you can here view or download the uninterpreted source code file. A member file download can also be achieved by clicking within a package contents listing on the according byte size field.

The Ruby Client

The elasticsearch Rubygem provides a low-level client for communicating with an Elasticsearch cluster, fully compatible with other official clients.

Full documentation is hosted at Github and 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 gem version, though:

Elasticsearch version Ruby gem version






Install the Ruby gem for Elasticsearch 1.x:

gem install elasticsearch

…​or add it do your Gemfile:

gem 'elasticsearch'

Install the Ruby gem for Elasticsearch 0.90.x:

gem install elasticsearch -v 0.4.10

…​or add it do your Gemfile:

gem 'elasticsearch', '~> 0.4'

Example Usage

require 'elasticsearch'

client = Elasticsearch::Client.new log: true


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

  • Pluggable connection selection strategies (round-robin, random, custom)

  • 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

The elasticsearch gem combines two separate Rubygems:

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 Rubydoc.

Keep in mind, that for optimal performance, you should use an HTTP library which supports persistent ("keep-alive") HTTP connections.


The elasticsearch-extensions Rubygem provides a number of extensions to the core client, such as an API to programmatically launch Elasticsearch clusters (eg. for testing purposes), and more.

Please see its documentation for more information.