elasticsearch-ruby 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +49 -0
- data/lib/elastic_search/client.rb +1 -1
- data/lib/elastic_search/request.rb +3 -4
- data/lib/elastic_search/response.rb +4 -3
- data/lib/elastic_search/search/results.rb +2 -1
- data/lib/elastic_search/type.rb +10 -0
- data/lib/elastic_search/version.rb +1 -1
- data/spec/elasticsearch/client_spec.rb +5 -1
- data/spec/elasticsearch/index_spec.rb +2 -1
- data/spec/elasticsearch/type_spec.rb +7 -0
- metadata +45 -13
data/README.markdown
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# elasticsearch-client
|
2
|
+
|
3
|
+
An elastic search ruby library with multiple transport support originall built
|
4
|
+
for use with [SoundTracking](http://www.soundtracking.com/).
|
5
|
+
|
6
|
+
> DISCLAIMER: Quite a bit more work to be done till production ready, use at your own
|
7
|
+
> risk! :)
|
8
|
+
|
9
|
+
Installation
|
10
|
+
------------
|
11
|
+
|
12
|
+
$ gem install elasticsearch-ruby
|
13
|
+
|
14
|
+
Usage
|
15
|
+
-----
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
|
19
|
+
transport = ElasticSearch::HTTPTransport.new(['http://localhost:9200'])
|
20
|
+
client = ElasticSearch::Client.new(transport)
|
21
|
+
|
22
|
+
index = client.create_index('twitter')
|
23
|
+
index['tweet'].put(1, { foo: 'bar' })
|
24
|
+
|
25
|
+
query = { query: { query_string: { query: 'bar' } } }
|
26
|
+
results = index['tweet'].search
|
27
|
+
|
28
|
+
results.total # 1
|
29
|
+
|
30
|
+
results.each do |result|
|
31
|
+
result.score # 1.0
|
32
|
+
result['foo'] # bar
|
33
|
+
end
|
34
|
+
|
35
|
+
client['twitter'].search(query).type # 'tweet'
|
36
|
+
|
37
|
+
```
|
38
|
+
|
39
|
+
TODO:
|
40
|
+
-----
|
41
|
+
|
42
|
+
* Better configuration support
|
43
|
+
* Failover and retry code
|
44
|
+
* Better unicode suppoort with Thrift
|
45
|
+
* Support for Memcache Transport
|
46
|
+
* Query Builder and block support
|
47
|
+
* Stats, Health lookup methods
|
48
|
+
* Better error handling
|
49
|
+
* Documentation
|
@@ -14,7 +14,7 @@ module ElasticSearch
|
|
14
14
|
|
15
15
|
def parameters
|
16
16
|
@stringified_parameters ||= @parameters.inject({}) do |options, (key, value)|
|
17
|
-
options[key.to_s] = value
|
17
|
+
options[key.to_s] = value.to_s
|
18
18
|
options
|
19
19
|
end if @parameters
|
20
20
|
end
|
@@ -24,10 +24,9 @@ module ElasticSearch
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def path
|
27
|
-
components = [@index, @type]
|
28
|
-
components << @id if @id
|
27
|
+
components = [@index, @type, @id]
|
29
28
|
components << "_#{@action.to_s}" if @action
|
30
|
-
components.compact.join("/")
|
29
|
+
"/#{components.compact.join("/")}"
|
31
30
|
end
|
32
31
|
end
|
33
32
|
end
|
@@ -14,7 +14,7 @@ module ElasticSearch
|
|
14
14
|
elsif self.body['exists'].eql?(false)
|
15
15
|
raise ElasticSearch::ItemMissingException, "_id: #{self.body['id']} NOT FOUND"
|
16
16
|
else
|
17
|
-
raise ElasticSearch::
|
17
|
+
raise ElasticSearch::NotFoundError
|
18
18
|
end
|
19
19
|
else
|
20
20
|
raise ElasticSearch::ResponseError, "#{self.body['status']}: #{self.body['error']}"
|
@@ -33,6 +33,7 @@ module ElasticSearch
|
|
33
33
|
end
|
34
34
|
|
35
35
|
class ResponseError < StandardError; end
|
36
|
-
class
|
37
|
-
class
|
36
|
+
class NotFoundError < StandardError; end
|
37
|
+
class IndexMissingException < NotFoundError; end
|
38
|
+
class ItemMissingException < NotFoundError; end
|
38
39
|
end
|
@@ -14,13 +14,14 @@ module ElasticSearch
|
|
14
14
|
end
|
15
15
|
|
16
16
|
class ResultItem < HashWithIndifferentAccess
|
17
|
-
attr_reader :index, :type, :id, :score
|
17
|
+
attr_reader :index, :type, :id, :score, :explanation
|
18
18
|
|
19
19
|
def initialize(hit)
|
20
20
|
@index = hit['_index']
|
21
21
|
@type = hit['_type']
|
22
22
|
@id = hit['_id']
|
23
23
|
@score = hit['_score']
|
24
|
+
@explanation = hit ['_explanation']
|
24
25
|
self.replace(hit['_source'])
|
25
26
|
end
|
26
27
|
end
|
data/lib/elastic_search/type.rb
CHANGED
@@ -47,6 +47,16 @@ module ElasticSearch
|
|
47
47
|
request = build_request({ method: :get, id: id.to_s, action: :mlt, parameters: parameters, body: doc })
|
48
48
|
end
|
49
49
|
|
50
|
+
def mapping
|
51
|
+
request = build_request(method: :get, action: :mapping)
|
52
|
+
execute(request).body
|
53
|
+
end
|
54
|
+
|
55
|
+
def mapping=(mapping)
|
56
|
+
request = build_request(method: :put, action: :mapping, body: mapping)
|
57
|
+
execute(request).status.eql?(200)
|
58
|
+
end
|
59
|
+
|
50
60
|
def delete_mapping
|
51
61
|
request = build_request({ method: :delete })
|
52
62
|
execute(request).status.eql?(200)
|
@@ -43,10 +43,14 @@ describe ElasticSearch::Client do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
describe :has_index? do
|
46
|
-
it "should
|
46
|
+
it "should return true if an index exists" do
|
47
47
|
client.create_index(TEST_INDEX).refresh
|
48
48
|
client.has_index?(TEST_INDEX).must_equal true
|
49
49
|
end
|
50
|
+
|
51
|
+
it "should return false if an index does not exist" do
|
52
|
+
client.has_index?(TEST_INDEX).must_equal false
|
53
|
+
end
|
50
54
|
end
|
51
55
|
|
52
56
|
describe :bulk do
|
@@ -85,7 +85,8 @@ describe ElasticSearch::Index do
|
|
85
85
|
|
86
86
|
describe :mapping do
|
87
87
|
it "should return the mapping" do
|
88
|
-
index.mapping
|
88
|
+
index[:tweet].mapping = { tweet: { properties: { message: { type: 'string' } } } }
|
89
|
+
index.mapping[TEST_INDEX]['tweet']['properties']['message']['type'].must_equal 'string'
|
89
90
|
end
|
90
91
|
end
|
91
92
|
|
@@ -51,6 +51,13 @@ describe ElasticSearch::Type do
|
|
51
51
|
results.total.must_equal 20
|
52
52
|
results.count.must_equal 10
|
53
53
|
end
|
54
|
+
|
55
|
+
it "should return an explanation if explain is passed as a parameter" do
|
56
|
+
type.put(1, { foo: 'bar' })
|
57
|
+
index.refresh
|
58
|
+
results = type.search(nil, q: 'bar', explain: true)
|
59
|
+
results.first.explanation.must_be_kind_of Hash
|
60
|
+
end
|
54
61
|
end
|
55
62
|
end
|
56
63
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elasticsearch-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-06-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thrift
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: activesupport
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: 3.0.0
|
33
38
|
type: :runtime
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 3.0.0
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: rake
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ! '>='
|
@@ -43,10 +53,15 @@ dependencies:
|
|
43
53
|
version: '0'
|
44
54
|
type: :development
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
47
62
|
- !ruby/object:Gem::Dependency
|
48
63
|
name: minitest
|
49
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
50
65
|
none: false
|
51
66
|
requirements:
|
52
67
|
- - ! '>='
|
@@ -54,10 +69,15 @@ dependencies:
|
|
54
69
|
version: '0'
|
55
70
|
type: :development
|
56
71
|
prerelease: false
|
57
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
58
78
|
- !ruby/object:Gem::Dependency
|
59
79
|
name: turn
|
60
|
-
requirement:
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
61
81
|
none: false
|
62
82
|
requirements:
|
63
83
|
- - ! '>='
|
@@ -65,7 +85,12 @@ dependencies:
|
|
65
85
|
version: '0'
|
66
86
|
type: :development
|
67
87
|
prerelease: false
|
68
|
-
version_requirements:
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
69
94
|
description: Ruby Driver for Elastic Search
|
70
95
|
email:
|
71
96
|
- edmund@edmundatwork.com
|
@@ -76,6 +101,7 @@ files:
|
|
76
101
|
- .gitignore
|
77
102
|
- .rvmrc
|
78
103
|
- Gemfile
|
104
|
+
- README.markdown
|
79
105
|
- Rakefile
|
80
106
|
- elastic_search.gemspec
|
81
107
|
- lib/elastic_search.rb
|
@@ -110,15 +136,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
110
136
|
- - ! '>='
|
111
137
|
- !ruby/object:Gem::Version
|
112
138
|
version: '0'
|
139
|
+
segments:
|
140
|
+
- 0
|
141
|
+
hash: -1939019870286825745
|
113
142
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
143
|
none: false
|
115
144
|
requirements:
|
116
145
|
- - ! '>='
|
117
146
|
- !ruby/object:Gem::Version
|
118
147
|
version: '0'
|
148
|
+
segments:
|
149
|
+
- 0
|
150
|
+
hash: -1939019870286825745
|
119
151
|
requirements: []
|
120
152
|
rubyforge_project: elasticsearch
|
121
|
-
rubygems_version: 1.8.
|
153
|
+
rubygems_version: 1.8.24
|
122
154
|
signing_key:
|
123
155
|
specification_version: 3
|
124
156
|
summary: Ruby Driver for Elastic Search
|