elastic_adapter 0.1.0 → 0.2.0
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.
- checksums.yaml +4 -4
- data/lib/elastic_adapter.rb +0 -10
- data/lib/elastic_adapter/index.rb +41 -74
- data/lib/elastic_adapter/version.rb +1 -1
- data/spec/integration/index/aggregation_spec.rb +1 -5
- data/spec/integration/index/count_spec.rb +6 -5
- data/spec/integration/index/get_spec.rb +7 -6
- data/spec/integration/index/index_spec.rb +1 -2
- data/spec/integration/index/search_spec.rb +6 -4
- data/spec/integration/index/shared_context.rb +0 -1
- data/spec/integration/index/suggest_spec.rb +1 -1
- data/spec/integration/index/validate_spec.rb +2 -2
- data/spec/unit/index_spec.rb +15 -27
- metadata +3 -33
- data/lib/elastic_adapter/response.rb +0 -25
- data/lib/elastic_adapter/responses/with_aggregations.rb +0 -9
- data/lib/elastic_adapter/responses/with_count.rb +0 -9
- data/lib/elastic_adapter/responses/with_exception.rb +0 -9
- data/lib/elastic_adapter/responses/with_hit.rb +0 -24
- data/lib/elastic_adapter/responses/with_hits.rb +0 -18
- data/lib/elastic_adapter/responses/with_suggestions.rb +0 -9
- data/lib/elastic_adapter/responses/with_validations.rb +0 -13
- data/spec/integration/index/create_index_spec.rb +0 -39
- data/spec/integration/index/delete_index_spec.rb +0 -29
- data/spec/integration/index/shared_examples.rb +0 -19
- data/spec/unit/response_spec.rb +0 -28
- data/spec/unit/responses/with_aggregations_spec.rb +0 -30
- data/spec/unit/responses/with_count_spec.rb +0 -22
- data/spec/unit/responses/with_exception_spec.rb +0 -17
- data/spec/unit/responses/with_hit_spec.rb +0 -49
- data/spec/unit/responses/with_hits_spec.rb +0 -79
- data/spec/unit/responses/with_suggestions_spec.rb +0 -33
- data/spec/unit/responses/with_validations_spec.rb +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fcd771ead4aea21340a2679050092a3013cf49b7
|
4
|
+
data.tar.gz: 3640999224cc2011557cbd0f1cd3e2234c786c79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3ff80d83d4ec56a12bdded63a752c197e7f7beb84fc4b135ef114fdea47df382adbf51e1a0315c8e62a018284dc6723cfba003a78b24c5cb32b22caf5c0dbcb
|
7
|
+
data.tar.gz: 12330e49c4cc65d118291167369a3c67051409a400cc222f30e1c898fb43e5078adba44de963f9b76eb327ac48d0b50c215457038b9e718ca01a15ac1c645641
|
data/lib/elastic_adapter.rb
CHANGED
@@ -2,16 +2,6 @@ require "elasticsearch"
|
|
2
2
|
|
3
3
|
require "elastic_adapter/version"
|
4
4
|
require "elastic_adapter/document_type"
|
5
|
-
require "elastic_adapter/response"
|
6
|
-
|
7
|
-
require "elastic_adapter/responses/with_exception"
|
8
|
-
require "elastic_adapter/responses/with_aggregations"
|
9
|
-
require "elastic_adapter/responses/with_validations"
|
10
|
-
require "elastic_adapter/responses/with_suggestions"
|
11
|
-
require "elastic_adapter/responses/with_hits"
|
12
|
-
require "elastic_adapter/responses/with_hit"
|
13
|
-
require "elastic_adapter/responses/with_count"
|
14
|
-
|
15
5
|
require "elastic_adapter/index"
|
16
6
|
|
17
7
|
begin
|
@@ -29,8 +29,6 @@ module ElasticAdapter
|
|
29
29
|
class Index
|
30
30
|
attr_reader :name, :settings, :document_type, :url, :log, :client
|
31
31
|
|
32
|
-
ELASTICSEARCH_ERRORS = [Elasticsearch::Transport::Transport::Error]
|
33
|
-
|
34
32
|
# @param [Hash] params
|
35
33
|
# @option params [String] :name required
|
36
34
|
# @option params [Hash] :settings required
|
@@ -56,28 +54,24 @@ module ElasticAdapter
|
|
56
54
|
#
|
57
55
|
# @see http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-create-index.html Elasticsearch create index
|
58
56
|
#
|
59
|
-
# @return [
|
57
|
+
# @return [Hash]
|
60
58
|
def create_index
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
)
|
69
|
-
end
|
59
|
+
client.indices.create(
|
60
|
+
index: name,
|
61
|
+
body: {
|
62
|
+
mappings: document_type.mappings,
|
63
|
+
settings: settings
|
64
|
+
}
|
65
|
+
)
|
70
66
|
end
|
71
67
|
|
72
68
|
# Deletes the index
|
73
69
|
#
|
74
70
|
# @see http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-delete-index.html Elasticsearch delete index
|
75
71
|
#
|
76
|
-
# @return [
|
72
|
+
# @return [Hash]
|
77
73
|
def delete_index
|
78
|
-
|
79
|
-
client.indices.delete index: name
|
80
|
-
end
|
74
|
+
client.indices.delete index: name
|
81
75
|
end
|
82
76
|
|
83
77
|
# Returns the document count for the index
|
@@ -85,11 +79,9 @@ module ElasticAdapter
|
|
85
79
|
# @see http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-count.html#search-count Elasticsearch count api
|
86
80
|
#
|
87
81
|
# @param [Hash] query a query to count the documents for a given query. Defaults to match all
|
88
|
-
# @return [
|
82
|
+
# @return [Hash] the count
|
89
83
|
def count(query = { query: { match_all: {} } })
|
90
|
-
|
91
|
-
client.count index: name, body: query
|
92
|
-
end.extend(Responses::WithCount)
|
84
|
+
client.count index: name, body: query
|
93
85
|
end
|
94
86
|
|
95
87
|
# Indexes a Hash or anything that responds to to_hash as a document
|
@@ -102,7 +94,7 @@ module ElasticAdapter
|
|
102
94
|
# test_index.index(id: 1, name: "foo")
|
103
95
|
#
|
104
96
|
# @param [Hash] document
|
105
|
-
# @return [
|
97
|
+
# @return [Hash]
|
106
98
|
def index(document)
|
107
99
|
doc = document.to_hash.merge({})
|
108
100
|
|
@@ -113,11 +105,7 @@ module ElasticAdapter
|
|
113
105
|
body: doc
|
114
106
|
}
|
115
107
|
|
116
|
-
|
117
|
-
client.index(params)
|
118
|
-
end
|
119
|
-
|
120
|
-
response
|
108
|
+
client.index(params)
|
121
109
|
end
|
122
110
|
|
123
111
|
# Returns the document with the given id from the index
|
@@ -127,13 +115,11 @@ module ElasticAdapter
|
|
127
115
|
# @param [Integer] id
|
128
116
|
# @return [ElasticAdapter::HitDecorator]
|
129
117
|
def get(id)
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
)
|
136
|
-
end.extend(Responses::WithHit)
|
118
|
+
client.get(
|
119
|
+
index: name,
|
120
|
+
type: document_type.name,
|
121
|
+
id: id
|
122
|
+
)
|
137
123
|
end
|
138
124
|
|
139
125
|
# Searches the index for documents matching the passed query.
|
@@ -145,17 +131,12 @@ module ElasticAdapter
|
|
145
131
|
# test_index.seach(query: {match: {foo: "bar"}})
|
146
132
|
#
|
147
133
|
# @param [Hash] query
|
148
|
-
# @return [
|
134
|
+
# @return [Hash]
|
149
135
|
def search(query)
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
)
|
155
|
-
end
|
156
|
-
.extend(Responses::WithSuggestions)
|
157
|
-
.extend(Responses::WithAggregations)
|
158
|
-
.extend(Responses::WithHits)
|
136
|
+
client.search(
|
137
|
+
index: name,
|
138
|
+
body: query
|
139
|
+
)
|
159
140
|
end
|
160
141
|
|
161
142
|
# Searches the index for suggestions for the passed suggest query
|
@@ -167,14 +148,12 @@ module ElasticAdapter
|
|
167
148
|
# test_index.seach(name_suggestions: {text: "foo", completion: {field: "name"}})
|
168
149
|
#
|
169
150
|
# @param [Hash] query
|
170
|
-
# @return [
|
151
|
+
# @return [Hash]
|
171
152
|
def suggest(query)
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
)
|
177
|
-
end.extend(Responses::WithSuggestions)
|
153
|
+
client.suggest(
|
154
|
+
index: name,
|
155
|
+
body: query
|
156
|
+
)
|
178
157
|
end
|
179
158
|
|
180
159
|
# Validates the passed query
|
@@ -182,36 +161,24 @@ module ElasticAdapter
|
|
182
161
|
# @see http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-validate.html Elasticsearch validate api
|
183
162
|
#
|
184
163
|
# @param [Hash] query
|
185
|
-
# @return [
|
164
|
+
# @return [Hash]
|
186
165
|
def validate(query)
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
)
|
193
|
-
end.extend(Responses::WithValidations)
|
166
|
+
client.indices.validate_query(
|
167
|
+
index: name,
|
168
|
+
explain: true,
|
169
|
+
body: query
|
170
|
+
)
|
194
171
|
end
|
195
172
|
|
196
|
-
# Executes a search request and
|
173
|
+
# Executes a search request and returns the response
|
197
174
|
#
|
198
175
|
# @param [Hash] query
|
199
|
-
# @return [
|
176
|
+
# @return [Hash]
|
200
177
|
def aggregate(query)
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
)
|
206
|
-
end.extend(Responses::WithAggregations)
|
207
|
-
end
|
208
|
-
|
209
|
-
private
|
210
|
-
|
211
|
-
def handle_api_call(*args)
|
212
|
-
Response.new(yield)
|
213
|
-
rescue *ELASTICSEARCH_ERRORS => e
|
214
|
-
Response.new(exception: e).extend(Responses::WithException)
|
178
|
+
client.search(
|
179
|
+
index: name,
|
180
|
+
body: query
|
181
|
+
)
|
215
182
|
end
|
216
183
|
end
|
217
184
|
end
|
@@ -29,12 +29,8 @@ module ElasticAdapter
|
|
29
29
|
@response = subject.aggregate(query)
|
30
30
|
end
|
31
31
|
|
32
|
-
it "is a WithAggregation" do
|
33
|
-
expect(@response.singleton_class).to be < Responses::WithAggregations
|
34
|
-
end
|
35
|
-
|
36
32
|
it "has a aggregation" do
|
37
|
-
expect(@response
|
33
|
+
expect(@response['aggregations']).not_to be_empty
|
38
34
|
end
|
39
35
|
end
|
40
36
|
end
|
@@ -10,14 +10,14 @@ module ElasticAdapter
|
|
10
10
|
create_test_index
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
13
|
after :all do
|
15
14
|
delete_test_index
|
16
15
|
end
|
17
16
|
|
17
|
+
before { @result = subject.count }
|
18
|
+
|
18
19
|
it "returns the amount of all documents" do
|
19
|
-
result
|
20
|
-
expect(result.count).to eq 0
|
20
|
+
expect(@result['count']).to eq 0
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -31,9 +31,10 @@ module ElasticAdapter
|
|
31
31
|
delete_test_index
|
32
32
|
end
|
33
33
|
|
34
|
+
before { @result = subject.count }
|
35
|
+
|
34
36
|
it "returns 1" do
|
35
|
-
result
|
36
|
-
expect(result.count).to eq 1
|
37
|
+
expect(@result['count']).to eq 1
|
37
38
|
end
|
38
39
|
end
|
39
40
|
end
|
@@ -22,13 +22,14 @@ module ElasticAdapter
|
|
22
22
|
describe "document" do
|
23
23
|
it "returns the document" do
|
24
24
|
expected = {
|
25
|
-
_index
|
26
|
-
_type
|
27
|
-
_id
|
28
|
-
_version
|
29
|
-
|
25
|
+
'_index' => 'test_index',
|
26
|
+
'_type' => "test_doc",
|
27
|
+
'_id' => "1",
|
28
|
+
'_version' => 1,
|
29
|
+
'found' => true,
|
30
|
+
'_source' => { 'foo' => 'bar' }
|
30
31
|
}
|
31
|
-
expect(response
|
32
|
+
expect(response).to eq expected
|
32
33
|
end
|
33
34
|
end
|
34
35
|
end
|
@@ -17,19 +17,21 @@ module ElasticAdapter
|
|
17
17
|
|
18
18
|
context "match_all" do
|
19
19
|
it "returns all documents" do
|
20
|
-
|
20
|
+
result = subject.search({query: {match_all: {}}})
|
21
|
+
expect(result['hits']['total']).to eq 2
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
24
25
|
context "zoo" do
|
25
26
|
let(:response) { subject.search(query: {match: {foo: "zoo"}})}
|
27
|
+
|
26
28
|
it "returns one document" do
|
27
|
-
expect(response
|
29
|
+
expect(response['hits']['total']).to eq 1
|
28
30
|
end
|
29
31
|
|
30
32
|
it "returns the wanted document" do
|
31
|
-
expect(response
|
32
|
-
expect(response
|
33
|
+
expect(response['hits']['hits'].first['_id']).to eq '2'
|
34
|
+
expect(response['hits']['hits'].first['_source']['foo']).to eq 'zoo'
|
33
35
|
end
|
34
36
|
end
|
35
37
|
end
|
@@ -31,7 +31,7 @@ module ElasticAdapter
|
|
31
31
|
let(:response) { subject.suggest(query) }
|
32
32
|
|
33
33
|
it "returns bar" do
|
34
|
-
expect(response[
|
34
|
+
expect(response['foo_suggest'].first['options'].first['text']).to eq 'bar'
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
@@ -24,7 +24,7 @@ module ElasticAdapter
|
|
24
24
|
|
25
25
|
describe "valid?" do
|
26
26
|
it "is false" do
|
27
|
-
expect(response
|
27
|
+
expect(response['valid']).to be false
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -34,7 +34,7 @@ module ElasticAdapter
|
|
34
34
|
let(:response) { subject.validate(query) }
|
35
35
|
|
36
36
|
it "is true" do
|
37
|
-
expect(response
|
37
|
+
expect(response['valid']).to eq true
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
data/spec/unit/index_spec.rb
CHANGED
@@ -110,9 +110,10 @@ module ElasticAdapter
|
|
110
110
|
subject.count(query)
|
111
111
|
end
|
112
112
|
|
113
|
-
it "returns
|
113
|
+
it "returns the response" do
|
114
114
|
expect(client).to receive(:count).and_return({})
|
115
|
-
|
115
|
+
result = subject.count(query)
|
116
|
+
expect(result).to eq({})
|
116
117
|
end
|
117
118
|
end
|
118
119
|
|
@@ -130,10 +131,10 @@ module ElasticAdapter
|
|
130
131
|
subject.index(doc)
|
131
132
|
end
|
132
133
|
|
133
|
-
it "returns
|
134
|
+
it "returns the response" do
|
134
135
|
expect(client).to receive(:index).and_return({})
|
135
136
|
result = subject.index(doc)
|
136
|
-
expect(result).to
|
137
|
+
expect(result).to eq({})
|
137
138
|
end
|
138
139
|
end
|
139
140
|
|
@@ -143,10 +144,10 @@ module ElasticAdapter
|
|
143
144
|
subject.get(1)
|
144
145
|
end
|
145
146
|
|
146
|
-
it "returns
|
147
|
+
it "returns the response" do
|
147
148
|
expect(client).to receive(:get).and_return({})
|
148
149
|
result = subject.get(1)
|
149
|
-
expect(result
|
150
|
+
expect(result).to eq({})
|
150
151
|
end
|
151
152
|
end
|
152
153
|
|
@@ -156,12 +157,10 @@ module ElasticAdapter
|
|
156
157
|
subject.search(query)
|
157
158
|
end
|
158
159
|
|
159
|
-
it "returns
|
160
|
+
it "returns the response" do
|
160
161
|
expect(client).to receive(:search).and_return({})
|
161
162
|
result = subject.search(query)
|
162
|
-
expect(result
|
163
|
-
expect(result.singleton_class).to be < Responses::WithSuggestions
|
164
|
-
expect(result.singleton_class).to be < Responses::WithAggregations
|
163
|
+
expect(result).to eq({})
|
165
164
|
end
|
166
165
|
end
|
167
166
|
|
@@ -171,10 +170,10 @@ module ElasticAdapter
|
|
171
170
|
subject.suggest(query)
|
172
171
|
end
|
173
172
|
|
174
|
-
it "returns
|
173
|
+
it "returns the response" do
|
175
174
|
expect(client).to receive(:suggest).and_return({})
|
176
175
|
result = subject.suggest(query)
|
177
|
-
expect(result
|
176
|
+
expect(result).to eq({})
|
178
177
|
end
|
179
178
|
end
|
180
179
|
|
@@ -184,10 +183,10 @@ module ElasticAdapter
|
|
184
183
|
subject.aggregate(query)
|
185
184
|
end
|
186
185
|
|
187
|
-
it "returns
|
186
|
+
it "returns the response" do
|
188
187
|
expect(client).to receive(:search).and_return({})
|
189
188
|
result = subject.aggregate(query)
|
190
|
-
expect(result
|
189
|
+
expect(result).to eq({})
|
191
190
|
end
|
192
191
|
end
|
193
192
|
|
@@ -197,21 +196,10 @@ module ElasticAdapter
|
|
197
196
|
subject.validate(query)
|
198
197
|
end
|
199
198
|
|
200
|
-
it "returns
|
199
|
+
it "returns the response" do
|
201
200
|
expect(indices).to receive(:validate_query).and_return({})
|
202
201
|
result = subject.validate(query)
|
203
|
-
expect(result
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
describe "error handling" do
|
208
|
-
before do
|
209
|
-
allow(client).to receive(:search).and_raise(Elasticsearch::Transport::Transport::Error)
|
210
|
-
end
|
211
|
-
|
212
|
-
it "returns a response with exception" do
|
213
|
-
result = subject.search(query)
|
214
|
-
expect(result.singleton_class).to be < Responses::WithException
|
202
|
+
expect(result).to eq({})
|
215
203
|
end
|
216
204
|
end
|
217
205
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elastic_adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kristopher Bredemeier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: elasticsearch
|
@@ -159,14 +159,6 @@ files:
|
|
159
159
|
- lib/elastic_adapter.rb
|
160
160
|
- lib/elastic_adapter/document_type.rb
|
161
161
|
- lib/elastic_adapter/index.rb
|
162
|
-
- lib/elastic_adapter/response.rb
|
163
|
-
- lib/elastic_adapter/responses/with_aggregations.rb
|
164
|
-
- lib/elastic_adapter/responses/with_count.rb
|
165
|
-
- lib/elastic_adapter/responses/with_exception.rb
|
166
|
-
- lib/elastic_adapter/responses/with_hit.rb
|
167
|
-
- lib/elastic_adapter/responses/with_hits.rb
|
168
|
-
- lib/elastic_adapter/responses/with_suggestions.rb
|
169
|
-
- lib/elastic_adapter/responses/with_validations.rb
|
170
162
|
- lib/elastic_adapter/version.rb
|
171
163
|
- spec/cassettes/ElasticAdapter_Index/_aggregate.yml
|
172
164
|
- spec/cassettes/ElasticAdapter_Index/_aggregate/response/has_a_aggregation.yml
|
@@ -212,13 +204,10 @@ files:
|
|
212
204
|
- spec/cassettes/ElasticAdapter_Index/_validate/valid_query/is_true.yml
|
213
205
|
- spec/integration/index/aggregation_spec.rb
|
214
206
|
- spec/integration/index/count_spec.rb
|
215
|
-
- spec/integration/index/create_index_spec.rb
|
216
|
-
- spec/integration/index/delete_index_spec.rb
|
217
207
|
- spec/integration/index/get_spec.rb
|
218
208
|
- spec/integration/index/index_spec.rb
|
219
209
|
- spec/integration/index/search_spec.rb
|
220
210
|
- spec/integration/index/shared_context.rb
|
221
|
-
- spec/integration/index/shared_examples.rb
|
222
211
|
- spec/integration/index/suggest_spec.rb
|
223
212
|
- spec/integration/index/unit_spec.rb
|
224
213
|
- spec/integration/index/validate_spec.rb
|
@@ -227,14 +216,6 @@ files:
|
|
227
216
|
- spec/unit/document_type_spec.rb
|
228
217
|
- spec/unit/elastic_adapter_spec.rb
|
229
218
|
- spec/unit/index_spec.rb
|
230
|
-
- spec/unit/response_spec.rb
|
231
|
-
- spec/unit/responses/with_aggregations_spec.rb
|
232
|
-
- spec/unit/responses/with_count_spec.rb
|
233
|
-
- spec/unit/responses/with_exception_spec.rb
|
234
|
-
- spec/unit/responses/with_hit_spec.rb
|
235
|
-
- spec/unit/responses/with_hits_spec.rb
|
236
|
-
- spec/unit/responses/with_suggestions_spec.rb
|
237
|
-
- spec/unit/responses/with_validations_spec.rb
|
238
219
|
homepage: https://github.com/kbredemeier/elastic_adapter
|
239
220
|
licenses:
|
240
221
|
- MIT
|
@@ -255,7 +236,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
255
236
|
version: '0'
|
256
237
|
requirements: []
|
257
238
|
rubyforge_project:
|
258
|
-
rubygems_version: 2.
|
239
|
+
rubygems_version: 2.5.1
|
259
240
|
signing_key:
|
260
241
|
specification_version: 4
|
261
242
|
summary: Repository like access to elasticseach indices
|
@@ -304,13 +285,10 @@ test_files:
|
|
304
285
|
- spec/cassettes/ElasticAdapter_Index/_validate/valid_query/is_true.yml
|
305
286
|
- spec/integration/index/aggregation_spec.rb
|
306
287
|
- spec/integration/index/count_spec.rb
|
307
|
-
- spec/integration/index/create_index_spec.rb
|
308
|
-
- spec/integration/index/delete_index_spec.rb
|
309
288
|
- spec/integration/index/get_spec.rb
|
310
289
|
- spec/integration/index/index_spec.rb
|
311
290
|
- spec/integration/index/search_spec.rb
|
312
291
|
- spec/integration/index/shared_context.rb
|
313
|
-
- spec/integration/index/shared_examples.rb
|
314
292
|
- spec/integration/index/suggest_spec.rb
|
315
293
|
- spec/integration/index/unit_spec.rb
|
316
294
|
- spec/integration/index/validate_spec.rb
|
@@ -319,12 +297,4 @@ test_files:
|
|
319
297
|
- spec/unit/document_type_spec.rb
|
320
298
|
- spec/unit/elastic_adapter_spec.rb
|
321
299
|
- spec/unit/index_spec.rb
|
322
|
-
- spec/unit/response_spec.rb
|
323
|
-
- spec/unit/responses/with_aggregations_spec.rb
|
324
|
-
- spec/unit/responses/with_count_spec.rb
|
325
|
-
- spec/unit/responses/with_exception_spec.rb
|
326
|
-
- spec/unit/responses/with_hit_spec.rb
|
327
|
-
- spec/unit/responses/with_hits_spec.rb
|
328
|
-
- spec/unit/responses/with_suggestions_spec.rb
|
329
|
-
- spec/unit/responses/with_validations_spec.rb
|
330
300
|
has_rdoc:
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require "delegate"
|
2
|
-
|
3
|
-
module ElasticAdapter
|
4
|
-
class Response < SimpleDelegator
|
5
|
-
def initialize(object)
|
6
|
-
__setobj__(symbolize_keys(object))
|
7
|
-
end
|
8
|
-
|
9
|
-
def object
|
10
|
-
__getobj__
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def symbolize_keys(obj)
|
16
|
-
if obj.is_a? Hash
|
17
|
-
Hash[obj.map { |k, v| [k.to_sym, symbolize_keys(v)] }]
|
18
|
-
elsif obj.is_a? Array
|
19
|
-
obj.map { |e| symbolize_keys(e) }
|
20
|
-
else
|
21
|
-
obj
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module ElasticAdapter
|
2
|
-
module Responses
|
3
|
-
module WithHit
|
4
|
-
class Hit < SimpleDelegator
|
5
|
-
attr_reader :version
|
6
|
-
|
7
|
-
def initialize(response)
|
8
|
-
response = response.dup
|
9
|
-
@found = response.delete(:found)
|
10
|
-
@version = response.delete(:version)
|
11
|
-
__setobj__(response)
|
12
|
-
end
|
13
|
-
|
14
|
-
def found?
|
15
|
-
@found
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def hit
|
20
|
-
@hit ||= Hit.new(object)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module ElasticAdapter
|
2
|
-
module Responses
|
3
|
-
module WithHits
|
4
|
-
class Hits < SimpleDelegator
|
5
|
-
attr_reader :count
|
6
|
-
|
7
|
-
def initialize(response)
|
8
|
-
@count = response.fetch(:hits, {}).fetch(:total, 0)
|
9
|
-
__setobj__(response.fetch(:hits, {}).fetch(:hits, []))
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def hits
|
14
|
-
@hits ||= Hits.new(object)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require_relative "./shared_context.rb"
|
2
|
-
|
3
|
-
module ElasticAdapter
|
4
|
-
describe Index do
|
5
|
-
include_context "index context"
|
6
|
-
|
7
|
-
describe "#create_index", :vcr do
|
8
|
-
context "index is present" do
|
9
|
-
before :all do
|
10
|
-
create_test_index
|
11
|
-
end
|
12
|
-
|
13
|
-
after :all do
|
14
|
-
delete_test_index
|
15
|
-
end
|
16
|
-
|
17
|
-
let(:response) { subject.create_index }
|
18
|
-
|
19
|
-
describe "response" do
|
20
|
-
# TODO fix this
|
21
|
-
# Somehow VCR doesn't record the requests for the current context
|
22
|
-
include_examples "response with exception"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context "index not present" do
|
27
|
-
after :each do
|
28
|
-
delete_test_index
|
29
|
-
end
|
30
|
-
|
31
|
-
let(:response) { subject.create_index }
|
32
|
-
|
33
|
-
describe "response" do
|
34
|
-
include_examples "response without exception"
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require_relative "./shared_context.rb"
|
2
|
-
|
3
|
-
module ElasticAdapter
|
4
|
-
describe Index do
|
5
|
-
include_context "index context"
|
6
|
-
|
7
|
-
describe "#delete_index", :vcr do
|
8
|
-
context "index present" do
|
9
|
-
let(:response) { subject.delete_index }
|
10
|
-
|
11
|
-
before :each do |example|
|
12
|
-
create_test_index prefix: vcr_cassette_name_for(example.metadata)
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "repsonse" do
|
16
|
-
include_examples "response without exception"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context "index not present" do
|
21
|
-
let(:response) { subject.delete_index }
|
22
|
-
|
23
|
-
describe "repsonse" do
|
24
|
-
include_examples "response with exception"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
RSpec.shared_examples "response without exception" do
|
2
|
-
it "is a Response" do
|
3
|
-
expect(response).to be_a ElasticAdapter::Response
|
4
|
-
end
|
5
|
-
|
6
|
-
it "has no exception" do
|
7
|
-
expect(response).not_to have_key :exception
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
RSpec.shared_examples "response with exception" do
|
12
|
-
it "is a Response" do
|
13
|
-
expect(response).to be_a ElasticAdapter::Response
|
14
|
-
end
|
15
|
-
|
16
|
-
it "has an exception" do
|
17
|
-
expect(response).to have_key :exception
|
18
|
-
end
|
19
|
-
end
|
data/spec/unit/response_spec.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
module ElasticAdapter
|
4
|
-
describe Response do
|
5
|
-
let(:object) {{
|
6
|
-
"foo" => { "bim" => "bam" },
|
7
|
-
"bar" => [
|
8
|
-
{ "biz" => "buz" }
|
9
|
-
],
|
10
|
-
"boo" => "bam"
|
11
|
-
}}
|
12
|
-
|
13
|
-
subject { Response.new(object) }
|
14
|
-
|
15
|
-
describe "symbolize keys" do
|
16
|
-
it "symbolizes all keys" do
|
17
|
-
expected = {
|
18
|
-
foo: { bim: "bam" },
|
19
|
-
bar: [
|
20
|
-
{ biz: "buz" }
|
21
|
-
],
|
22
|
-
boo: "bam"
|
23
|
-
}
|
24
|
-
expect(subject.object).to eq expected
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
module ElasticAdapter
|
4
|
-
describe Responses::WithAggregations do
|
5
|
-
let(:plain_response) {{
|
6
|
-
aggregations: {
|
7
|
-
products: {
|
8
|
-
doc_count_error_upper_bound: 46,
|
9
|
-
buckets: [
|
10
|
-
{
|
11
|
-
key: "Product A",
|
12
|
-
doc_count: 100
|
13
|
-
},
|
14
|
-
{
|
15
|
-
key: "Product Z",
|
16
|
-
doc_count: 52
|
17
|
-
}
|
18
|
-
]
|
19
|
-
}
|
20
|
-
}
|
21
|
-
}}
|
22
|
-
subject { Response.new(plain_response).extend(Responses::WithAggregations) }
|
23
|
-
|
24
|
-
describe "#aggregations" do
|
25
|
-
it "includes the products aggregation" do
|
26
|
-
expect(subject.aggregations).to eq plain_response[:aggregations]
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
module ElasticAdapter
|
4
|
-
describe Responses::WithCount do
|
5
|
-
let(:plain_response) {{
|
6
|
-
count: 1,
|
7
|
-
shards: {
|
8
|
-
total: 5,
|
9
|
-
successful: 5,
|
10
|
-
failed: 0
|
11
|
-
}
|
12
|
-
}}
|
13
|
-
|
14
|
-
subject { Response.new(plain_response).extend(Responses::WithCount) }
|
15
|
-
|
16
|
-
describe "#count" do
|
17
|
-
it "returns the count" do
|
18
|
-
expect(subject.count).to eq 1
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
module ElasticAdapter
|
4
|
-
describe Responses::WithException do
|
5
|
-
let(:plain_response) {{
|
6
|
-
exception: ArgumentError.new()
|
7
|
-
}}
|
8
|
-
|
9
|
-
subject { Response.new(plain_response).extend(Responses::WithException) }
|
10
|
-
|
11
|
-
describe "#exception" do
|
12
|
-
it "returns the exception" do
|
13
|
-
expect(subject.exception).to be plain_response[:exception]
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
module ElasticAdapter
|
4
|
-
describe Responses::WithHits do
|
5
|
-
let(:plain_response) {{
|
6
|
-
index: "twitter",
|
7
|
-
type: "tweet",
|
8
|
-
id: "1",
|
9
|
-
version: 1,
|
10
|
-
found: true,
|
11
|
-
source: {
|
12
|
-
user: "kimchy",
|
13
|
-
postDate: "2009-11-15T14:12:12",
|
14
|
-
message: "trying out Elasticsearch"
|
15
|
-
}
|
16
|
-
}}
|
17
|
-
subject { Response.new(plain_response).extend(Responses::WithHit) }
|
18
|
-
|
19
|
-
describe "#hit" do
|
20
|
-
it "is the hit" do
|
21
|
-
doc = {
|
22
|
-
index: "twitter",
|
23
|
-
type: "tweet",
|
24
|
-
id: "1",
|
25
|
-
source: {
|
26
|
-
user: "kimchy",
|
27
|
-
postDate: "2009-11-15T14:12:12",
|
28
|
-
message: "trying out Elasticsearch"
|
29
|
-
}
|
30
|
-
}
|
31
|
-
|
32
|
-
expect(subject.hit).to eq doc
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
describe "#found?" do
|
37
|
-
it "returns true" do
|
38
|
-
expect(subject.hit.found?).to be true
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe "#found" do
|
43
|
-
it "returns the version" do
|
44
|
-
expect(subject.hit.version).to eq 1
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,79 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
module ElasticAdapter
|
4
|
-
describe Responses::WithHits do
|
5
|
-
context "with hits" do
|
6
|
-
let(:plain_response) {{
|
7
|
-
shards: {
|
8
|
-
total: 5,
|
9
|
-
successful: 5,
|
10
|
-
failed: 0
|
11
|
-
},
|
12
|
-
hits: {
|
13
|
-
total: 100,
|
14
|
-
hits: [
|
15
|
-
{
|
16
|
-
index: "twitter",
|
17
|
-
type: "tweet",
|
18
|
-
id: "1",
|
19
|
-
source: {
|
20
|
-
user: "kimchy",
|
21
|
-
postDate: "2009-11-15T14:12:12",
|
22
|
-
message: "trying out Elasticsearch"
|
23
|
-
}
|
24
|
-
}
|
25
|
-
]
|
26
|
-
}
|
27
|
-
}}
|
28
|
-
|
29
|
-
subject { Response.new(plain_response).extend(Responses::WithHits) }
|
30
|
-
|
31
|
-
describe "#hits" do
|
32
|
-
it "includes the hit in a flattened format" do
|
33
|
-
doc = {
|
34
|
-
index: "twitter",
|
35
|
-
type: "tweet",
|
36
|
-
id: "1",
|
37
|
-
source: {
|
38
|
-
user: "kimchy",
|
39
|
-
postDate: "2009-11-15T14:12:12",
|
40
|
-
message: "trying out Elasticsearch"
|
41
|
-
}
|
42
|
-
}
|
43
|
-
|
44
|
-
expect(subject.hits).to include doc
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "#count" do
|
48
|
-
it "returns the count" do
|
49
|
-
expect(subject.hits.count).to be plain_response[:hits][:total]
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context "without hits" do
|
56
|
-
let(:plain_response) {{
|
57
|
-
shards: {
|
58
|
-
total: 5,
|
59
|
-
successful: 5,
|
60
|
-
failed: 0
|
61
|
-
},
|
62
|
-
hits: {
|
63
|
-
total: 0,
|
64
|
-
hits: []
|
65
|
-
}
|
66
|
-
}}
|
67
|
-
|
68
|
-
subject { Response.new(plain_response).extend(Responses::WithHits) }
|
69
|
-
|
70
|
-
describe "#hits" do
|
71
|
-
describe "#count" do
|
72
|
-
it "returns 0" do
|
73
|
-
expect(subject.hits.count).to eq 0
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
module ElasticAdapter
|
4
|
-
describe Responses::WithSuggestions do
|
5
|
-
let(:plain_response) {{
|
6
|
-
shards: {
|
7
|
-
total: 5, successful: 5, failed: 0
|
8
|
-
},
|
9
|
-
suggest: {
|
10
|
-
foo_suggest: [
|
11
|
-
{
|
12
|
-
text: "ba",
|
13
|
-
offset: 0,
|
14
|
-
length: 2,
|
15
|
-
options: [
|
16
|
-
{
|
17
|
-
text: "bar",
|
18
|
-
score: 1.0
|
19
|
-
}
|
20
|
-
]
|
21
|
-
}
|
22
|
-
]
|
23
|
-
}
|
24
|
-
}}
|
25
|
-
subject { Response.new(plain_response).extend(Responses::WithSuggestions) }
|
26
|
-
|
27
|
-
describe "#suggestions" do
|
28
|
-
it "includes the suggestion" do
|
29
|
-
expect(subject.suggestions).to eq plain_response[:suggest]
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
module ElasticAdapter
|
4
|
-
describe Responses::WithValidations do
|
5
|
-
let(:plain_response) {{
|
6
|
-
valid: false,
|
7
|
-
shards: {
|
8
|
-
total: 1,
|
9
|
-
successful: 1,
|
10
|
-
failed: 0
|
11
|
-
},
|
12
|
-
explanations: [
|
13
|
-
{
|
14
|
-
index: "twitter",
|
15
|
-
valid: false,
|
16
|
-
error: "some error message"
|
17
|
-
}
|
18
|
-
]
|
19
|
-
}}
|
20
|
-
subject { Response.new(plain_response).extend(Responses::WithValidations) }
|
21
|
-
|
22
|
-
describe "#explanations" do
|
23
|
-
it "includes the explanation" do
|
24
|
-
expect(subject.explanations).to eq plain_response[:explanations]
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe "#valid?" do
|
29
|
-
it "returns false" do
|
30
|
-
expect(subject.valid?).to be false
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|