This repository contains Ruby integrations for Elasticsearch.
elasticsearch library is a wrapper for two separate libraries:
elasticsearch-transport, which provides a low-level Ruby client for connecting to an Elasticsearch cluster
elasticsearch-api, which provides a Ruby API for the Elasticsearch RESTful API
require 'elasticsearch' client = Elasticsearch::Client.new log: true # if you specify Elasticsearch host # client = Elasticsearch::Client.new url: 'http://localhost:9200', log: true client.transport.reload_connections! client.cluster.health client.search q: 'test' # etc.
doc/examples for some practical examples.
For optimal performance, you should use a HTTP library which supports persistent ("keep-alive") connections, e.g. Patron or Typhoeus. These libraries are not dependencies of the Elasticsearch gems. Ensure you define a dependency for a HTTP library in your own application.
This repository contains these additional Ruby libraries:
elasticsearch-extensions, which provides a set of extensions to the base library,
elasticsearch-dsl, which provides a Ruby API for the Elasticsearch Query DSL,
elasticsearch-xpack, which provides a Ruby API for X-Pack APIs. This API is going to be merged into
Please see their respective READMEs for information and documentation.
For integration with Ruby models and Rails applications, see the elasticsearch-rails project.
The Elasticsearch client is compatible with currently maintained Ruby versions. See Ruby Maintenance Branches. We don't provide support to versions which have reached their end of life.
The gem's version numbers follow Elasticsearch's major versions. The
master branch is compatible with the Elasticsearch
master branch, which is the next major version.
Use a release that matches the major version of Elasticsearch in your stack. Each client version is backwards compatible with all minor versions of the same major version. The client's API is compatible with Elasticsearch's API versions from 0.90 till current.
Check out Elastic product end of life dates to learn which releases are still actively supported and tested.
elasticsearch package from Rubygems:
gem install elasticsearch
To use an unreleased version, either add it to your
Gemfile for Bundler:
gem 'elasticsearch', git: 'git://github.com/elasticsearch/elasticsearch-ruby.git'
or install it from a source code checkout:
git clone https://github.com/elasticsearch/elasticsearch-ruby.git cd elasticsearch-ruby/elasticsearch bundle install rake install
To work on the code, clone and bootstrap the project first:
git clone https://github.com/elasticsearch/elasticsearch-ruby.git cd elasticsearch-ruby/ rake setup rake bundle
This will clone the Elasticsearch repository into the project, and run
bundle install in all subprojects.
To run tests, you need to start a testing cluster on port 9250, or provide a different one in the
TEST_CLUSTER_PORT environment variable.
There's a Rake task to start the testing cluster:
You can configure the port, path to the startup script, number of nodes, and other settings with environment variables:
TEST_CLUSTER_COMMAND=./tmp/builds/elasticsearch-2.0.0-SNAPSHOT/bin/elasticsearch \ TEST_CLUSTER_PORT=9250 \ TEST_CLUSTER_NODES=2 \ TEST_CLUSTER_NAME=my_cluster \ TEST_CLUSTER_PARAMS='-Xms500m -Xmx500m -D es.index.store.type=niofs' \ TEST_CLUSTER_TIMEOUT=120 \ rake test:cluster:start
To run tests against unreleased Elasticsearch versions, you can use the
rake elasticsearch:build Rake task to build Elasticsearch from the cloned source (use
rake elasticsearch:update to update the repository):
Note: If you have gems from the
elasticsearch family installed system-wide, and want to use development ones, prepend the command with
You can pass a branch name (tag, commit, ...) as the Rake task variable:
To run all the tests in all the subprojects, use the Rake task:
time rake test:all
This software is licensed under the Apache 2 license.