Skip to content
Native Java ElasticSearch for JRuby
Find file
Latest commit eed3a00 @jordansissel - version bump
Failed to load latest commit information.
lib Remove a missed debugging statement
test - Add tests (that pass now) to make sure BulkStream works.
CHANGELIST bump to 0.0.14 Update
Rakefile - version bump
jruby-elasticsearch.gemspec - version bump

Start with it:

Grab the latest ElasticSearch distribution, and unpack it. Set your CLASSPATH to include the *jar files in the /lib directory.

Something like the following will accomplish this:

CLASSPATH=$(ls ./elasticsearch-0.20.6/lib/*.jar | tr '\n' ':')

To use from with Logstash source to get the appropriate jars for jruby-elasticsearch:

CLASSPATH=$(ls ./elasticsearch-0.20.6/lib/*.jar | tr '\n' ':') bin/logstash irb

Then to use the library in your code:

require "jruby-elasticsearch"
client =

DSL Example

client =
req = client.index("twitter", "tweet") do
  hello "world"     
  foo "bar"


# The above will index this document:
# {
#   "hello": "world",
#   "foo": "bar"<
# }

# Async w/ callback.
req.execute do |response|
  puts "Response; #{response}"

Non-DSL Example:

client =
#                  <index  >, <type   >, <id>, <data>
req = client.index("twitter", "fizzle2", nil, {
  "hello" => "world",
  "number" => rand(5000)

More complex method of indexing.

data = { "fizzle" => "dazzle", "pants" => "off" }
req = client.index("twitter", "tweet", data)

# Set up async callbacks
done = false
req.on(:success) do |response|
  puts "Got response: #{response.inspect}"
  done = true
end.on(:failure) do |exception|
  puts "Got failure: #{exception.inspect}"
  puts exception.backtrace
  done = true

# Execute it, but do it asynchronously.

# Wait until we are done.
while !done
  sleep 1


# Example 1, method chaining
# Returns
# querys for "some query" and asks for 30 results"some query").size(30).execute!

# Example 2, DSL do
  query "some query"

  # histogram, bucketed by 10000
  histogram "some field", 10000

  # how many results
  size 100
end.execute do |response|
  # response ==
Something went wrong with that request. Please try again.