jruby-elasticsearch 0.0.10 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/jruby-elasticsearch/bulkrequest.rb +11 -4
- data/lib/jruby-elasticsearch/client.rb +7 -0
- data/lib/jruby-elasticsearch.rb +1 -0
- data/test/test_integration.rb +72 -0
- metadata +24 -34
@@ -5,9 +5,8 @@ class ElasticSearch::BulkRequest < ElasticSearch::Request
|
|
5
5
|
# Create a new index request.
|
6
6
|
def initialize(client)
|
7
7
|
@client = client
|
8
|
-
|
9
|
-
|
10
|
-
super
|
8
|
+
@prep = @client.prepareBulk()
|
9
|
+
super()
|
11
10
|
end
|
12
11
|
|
13
12
|
# Execute this index request.
|
@@ -15,7 +14,7 @@ class ElasticSearch::BulkRequest < ElasticSearch::Request
|
|
15
14
|
#
|
16
15
|
# If a block is given, register it for both failure and success.
|
17
16
|
def execute(&block)
|
18
|
-
use_callback(&block) if block_given
|
17
|
+
use_callback(&block) if block_given?
|
19
18
|
action = @prep.execute(@handler)
|
20
19
|
return action
|
21
20
|
end
|
@@ -25,6 +24,14 @@ class ElasticSearch::BulkRequest < ElasticSearch::Request
|
|
25
24
|
return @prep.execute.actionGet()
|
26
25
|
end
|
27
26
|
|
27
|
+
def index(index, type, id=nil, data={})
|
28
|
+
req = org.elasticsearch.action.index.IndexRequest.new(index)
|
29
|
+
req.type(type) if type
|
30
|
+
req.id(id.to_s) if id
|
31
|
+
req.source(data)
|
32
|
+
@prep.add(req)
|
33
|
+
end
|
34
|
+
|
28
35
|
def <<(request)
|
29
36
|
@prep.add(request)
|
30
37
|
end # def <<
|
@@ -49,6 +49,13 @@ class ElasticSearch::Client
|
|
49
49
|
|
50
50
|
end # def initialize
|
51
51
|
|
52
|
+
# Get a new BulkRequest for sending multiple updates to elasticsearch in one
|
53
|
+
# request.
|
54
|
+
public
|
55
|
+
def bulk
|
56
|
+
ElasticSearch::BulkRequest.new(@client)
|
57
|
+
end # def bulk
|
58
|
+
|
52
59
|
# Index a new document
|
53
60
|
#
|
54
61
|
# args:
|
data/lib/jruby-elasticsearch.rb
CHANGED
@@ -0,0 +1,72 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
|
3
|
+
class TestElasticSearch < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
# Require all the elasticsearch libs
|
6
|
+
raise "Please set ELASTICSEARCH_HOME" if ENV['ELASTICSEARCH_HOME'].nil?
|
7
|
+
Dir[File.join(ENV['ELASTICSEARCH_HOME'],"lib/*.jar")].each do |jar|
|
8
|
+
require jar
|
9
|
+
end
|
10
|
+
|
11
|
+
$:.unshift("lib")
|
12
|
+
require "jruby-elasticsearch"
|
13
|
+
|
14
|
+
# Start a local elasticsearch node
|
15
|
+
builder = org.elasticsearch.node.NodeBuilder.nodeBuilder
|
16
|
+
builder.local(true)
|
17
|
+
@elasticsearch = builder.node
|
18
|
+
@elasticsearch.start
|
19
|
+
|
20
|
+
# Create a client which will find a nearby elasticsearch cluster using
|
21
|
+
# the default discovery mechanism.
|
22
|
+
@client = ElasticSearch::Client.new({:type => :local})
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_index_asynchronously
|
26
|
+
data = { "fizzle" => "dazzle", "pants" => "off" }
|
27
|
+
req = @client.index("twitter", "tweet", data)
|
28
|
+
|
29
|
+
# Set up async callbacks
|
30
|
+
done = false
|
31
|
+
req.on(:success) do |response|
|
32
|
+
assert_not_nil response
|
33
|
+
done = true
|
34
|
+
end.on(:failure) do |exception|
|
35
|
+
raise exception
|
36
|
+
done = true
|
37
|
+
end
|
38
|
+
|
39
|
+
# Execute it, but do it asynchronously.
|
40
|
+
req.execute
|
41
|
+
|
42
|
+
# Wait until we are done.
|
43
|
+
while !done
|
44
|
+
sleep 1
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_bulk_index_asynchronously
|
49
|
+
data = { "fizzle" => "dazzle", "pants" => "off" }
|
50
|
+
bulk = @client.bulk
|
51
|
+
bulk.index("twitter", "tweet1", data)
|
52
|
+
bulk.index("twitter", "tweet2")
|
53
|
+
|
54
|
+
# Set up async callbacks
|
55
|
+
done = false
|
56
|
+
bulk.on(:success) do |response|
|
57
|
+
assert_not_nil response
|
58
|
+
done = true
|
59
|
+
end.on(:failure) do |exception|
|
60
|
+
raise exception
|
61
|
+
done = true
|
62
|
+
end
|
63
|
+
|
64
|
+
# Execute it, but do it asynchronously.
|
65
|
+
bulk.execute
|
66
|
+
|
67
|
+
# Wait until we are done.
|
68
|
+
while !done
|
69
|
+
sleep 1
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
metadata
CHANGED
@@ -1,27 +1,22 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jruby-elasticsearch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 11
|
5
4
|
prerelease:
|
6
|
-
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 10
|
10
|
-
version: 0.0.10
|
5
|
+
version: 0.0.11
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
|
-
- Jordan Sissel
|
8
|
+
- Jordan Sissel
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
12
|
|
18
|
-
date: 2011-
|
13
|
+
date: 2011-10-11 00:00:00 -07:00
|
19
14
|
default_executable:
|
20
15
|
dependencies: []
|
21
16
|
|
22
17
|
description: ...
|
23
18
|
email:
|
24
|
-
- jls@semicomplete.com
|
19
|
+
- jls@semicomplete.com
|
25
20
|
executables: []
|
26
21
|
|
27
22
|
extensions: []
|
@@ -29,47 +24,42 @@ extensions: []
|
|
29
24
|
extra_rdoc_files: []
|
30
25
|
|
31
26
|
files:
|
32
|
-
- lib/jruby-elasticsearch.rb
|
33
|
-
- lib/jruby-elasticsearch/
|
34
|
-
- lib/jruby-elasticsearch/
|
35
|
-
- lib/jruby-elasticsearch/actionlistener.rb
|
36
|
-
- lib/jruby-elasticsearch/searchrequest.rb
|
37
|
-
- lib/jruby-elasticsearch/
|
38
|
-
- lib/jruby-elasticsearch/
|
39
|
-
- lib/jruby-elasticsearch/
|
40
|
-
- lib/jruby-elasticsearch/client.rb
|
27
|
+
- lib/jruby-elasticsearch.rb
|
28
|
+
- lib/jruby-elasticsearch/indexrequest.rb
|
29
|
+
- lib/jruby-elasticsearch/bulkstream.rb
|
30
|
+
- lib/jruby-elasticsearch/actionlistener.rb
|
31
|
+
- lib/jruby-elasticsearch/searchrequest.rb
|
32
|
+
- lib/jruby-elasticsearch/namespace.rb
|
33
|
+
- lib/jruby-elasticsearch/bulkrequest.rb
|
34
|
+
- lib/jruby-elasticsearch/request.rb
|
35
|
+
- lib/jruby-elasticsearch/client.rb
|
36
|
+
- test/test_integration.rb
|
41
37
|
has_rdoc: true
|
42
38
|
homepage: https://github.com/jordansissel/jruby-elasticsearch
|
43
39
|
licenses:
|
44
|
-
- Apache License (2.0)
|
40
|
+
- Apache License (2.0)
|
45
41
|
post_install_message:
|
46
42
|
rdoc_options: []
|
47
43
|
|
48
44
|
require_paths:
|
49
|
-
- lib
|
50
|
-
- lib
|
45
|
+
- lib
|
46
|
+
- lib
|
51
47
|
required_ruby_version: !ruby/object:Gem::Requirement
|
52
48
|
none: false
|
53
49
|
requirements:
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
segments:
|
58
|
-
- 0
|
59
|
-
version: "0"
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
60
53
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
54
|
none: false
|
62
55
|
requirements:
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
segments:
|
67
|
-
- 0
|
68
|
-
version: "0"
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
69
59
|
requirements: []
|
70
60
|
|
71
61
|
rubyforge_project:
|
72
|
-
rubygems_version: 1.
|
62
|
+
rubygems_version: 1.5.1
|
73
63
|
signing_key:
|
74
64
|
specification_version: 3
|
75
65
|
summary: JRuby API for ElasticSearch using the native ES Java API
|