elastomer-client 3.2.3 → 6.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.devcontainer/devcontainer.json +46 -0
- data/.devcontainer/postCreateCommand.sh +4 -0
- data/.github/dependabot.yaml +11 -0
- data/.github/workflows/main.yml +45 -0
- data/.github/workflows/rubocop.yml +15 -0
- data/.gitignore +1 -1
- data/.rubocop.yml +13 -65
- data/.ruby-version +1 -0
- data/CHANGELOG.md +73 -0
- data/Gemfile +18 -1
- data/README.md +110 -51
- data/Rakefile +3 -1
- data/docker/compose.yaml +71 -0
- data/docker/elasticsearch8plus.yml +13 -0
- data/docs/README.md +4 -5
- data/docs/bulk_indexing.md +1 -1
- data/docs/client.md +20 -33
- data/docs/cluster.md +8 -8
- data/docs/docs.md +5 -5
- data/docs/index.md +4 -4
- data/docs/multi_search.md +1 -1
- data/docs/notifications.md +3 -3
- data/docs/scan_scroll.md +1 -1
- data/docs/snapshots.md +1 -1
- data/docs/templates.md +1 -1
- data/elastomer-client.gemspec +7 -16
- data/lib/{elastomer → elastomer_client}/client/bulk.rb +70 -47
- data/lib/{elastomer → elastomer_client}/client/cluster.rb +18 -16
- data/lib/{elastomer → elastomer_client}/client/delete_by_query.rb +6 -4
- data/lib/{elastomer → elastomer_client}/client/docs.rb +82 -72
- data/lib/{elastomer → elastomer_client}/client/errors.rb +7 -17
- data/lib/{elastomer → elastomer_client}/client/index.rb +55 -79
- data/lib/{elastomer → elastomer_client}/client/multi_percolate.rb +7 -5
- data/lib/{elastomer → elastomer_client}/client/multi_search.rb +5 -3
- data/lib/{elastomer → elastomer_client}/client/native_delete_by_query.rb +6 -6
- data/lib/{elastomer → elastomer_client}/client/nodes.rb +11 -10
- data/lib/{elastomer → elastomer_client}/client/percolator.rb +9 -10
- data/lib/elastomer_client/client/reindex.rb +29 -0
- data/lib/{elastomer → elastomer_client}/client/repository.rb +7 -5
- data/lib/{elastomer → elastomer_client}/client/rest_api_spec/api_spec.rb +7 -6
- data/lib/{elastomer → elastomer_client}/client/rest_api_spec/api_spec_v5_6.rb +1 -1
- data/lib/elastomer_client/client/rest_api_spec/api_spec_v8_13.rb +7567 -0
- data/lib/elastomer_client/client/rest_api_spec/api_spec_v8_7.rb +6553 -0
- data/lib/{elastomer → elastomer_client}/client/rest_api_spec/rest_api.rb +5 -3
- data/lib/{elastomer → elastomer_client}/client/rest_api_spec.rb +3 -2
- data/lib/{elastomer → elastomer_client}/client/scroller.rb +17 -16
- data/lib/{elastomer → elastomer_client}/client/snapshot.rb +10 -8
- data/lib/{elastomer → elastomer_client}/client/tasks.rb +9 -13
- data/lib/{elastomer → elastomer_client}/client/template.rb +10 -9
- data/lib/elastomer_client/client/update_by_query.rb +50 -0
- data/lib/{elastomer → elastomer_client}/client.rb +51 -62
- data/lib/{elastomer → elastomer_client}/core_ext/time.rb +2 -0
- data/lib/{elastomer → elastomer_client}/middleware/compress.rb +2 -2
- data/lib/{elastomer → elastomer_client}/middleware/encode_json.rb +4 -2
- data/lib/{elastomer → elastomer_client}/middleware/limit_size.rb +5 -3
- data/lib/{elastomer → elastomer_client}/middleware/opaque_id.rb +10 -7
- data/lib/{elastomer → elastomer_client}/middleware/parse_json.rb +5 -3
- data/lib/{elastomer → elastomer_client}/notifications.rb +17 -15
- data/lib/elastomer_client/version.rb +9 -0
- data/lib/elastomer_client/version_support.rb +24 -0
- data/script/bootstrap +4 -2
- data/script/console +3 -1
- data/script/generate-rest-api-spec +77 -22
- data/test/assertions.rb +32 -39
- data/test/client/bulk_test.rb +166 -141
- data/test/client/cluster_test.rb +35 -13
- data/test/client/docs_test.rb +387 -274
- data/test/client/errors_test.rb +38 -40
- data/test/client/index_test.rb +243 -202
- data/test/client/multi_percolate_test.rb +46 -41
- data/test/client/multi_search_test.rb +122 -67
- data/test/client/native_delete_by_query_test.rb +96 -88
- data/test/client/nodes_test.rb +21 -10
- data/test/client/percolator_test.rb +19 -14
- data/test/client/reindex_test.rb +76 -0
- data/test/client/repository_test.rb +31 -19
- data/test/client/rest_api_spec/api_spec_test.rb +13 -11
- data/test/client/rest_api_spec/rest_api_test.rb +9 -7
- data/test/client/scroller_test.rb +44 -70
- data/test/client/snapshot_test.rb +38 -21
- data/test/client/stubbed_client_test.rb +7 -4
- data/test/client/tasks_test.rb +12 -17
- data/test/client/template_test.rb +34 -13
- data/test/client/update_by_query_test.rb +137 -0
- data/test/client_test.rb +158 -92
- data/test/core_ext/time_test.rb +14 -12
- data/test/middleware/encode_json_test.rb +18 -7
- data/test/middleware/opaque_id_test.rb +18 -14
- data/test/middleware/parse_json_test.rb +17 -9
- data/test/mock_response.rb +30 -0
- data/test/notifications_test.rb +15 -8
- data/test/test_helper.rb +40 -97
- data/test/version_support_test.rb +13 -78
- metadata +60 -208
- data/.overcommit.yml +0 -5
- data/.travis.yml +0 -34
- data/docker/docker-compose.cibuild.yml +0 -8
- data/docker/docker-compose.es24.yml +0 -34
- data/docker/docker-compose.es56.yml +0 -37
- data/docs/warmers.md +0 -3
- data/lib/elastomer/client/app_delete_by_query.rb +0 -144
- data/lib/elastomer/client/rest_api_spec/api_spec_v2_3.rb +0 -2232
- data/lib/elastomer/client/rest_api_spec/api_spec_v2_4.rb +0 -2250
- data/lib/elastomer/client/warmer.rb +0 -98
- data/lib/elastomer/version.rb +0 -7
- data/lib/elastomer/version_support.rb +0 -182
- data/script/cibuild +0 -103
- data/script/cibuild-elastomer-client +0 -1
- data/script/cibuild-elastomer-client-es24 +0 -8
- data/script/cibuild-elastomer-client-es56 +0 -8
- data/test/client/app_delete_by_query_test.rb +0 -192
- data/test/client/es_5_x_warmer_test.rb +0 -13
- data/test/client/warmer_test.rb +0 -60
data/test/client/docs_test.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative "../test_helper"
|
2
4
|
|
3
|
-
describe
|
5
|
+
describe ElastomerClient::Client::Docs do
|
4
6
|
|
5
7
|
before do
|
6
8
|
@name = "elastomer-docs-test"
|
@@ -8,27 +10,18 @@ describe Elastomer::Client::Docs do
|
|
8
10
|
|
9
11
|
unless @index.exists?
|
10
12
|
@index.create \
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:
|
14
|
-
|
15
|
-
:
|
16
|
-
|
17
|
-
:author => $client.version_support.keyword
|
18
|
-
}
|
19
|
-
},
|
20
|
-
:doc2 => {
|
21
|
-
:_source => { :enabled => true }, :_all => { :enabled => false },
|
22
|
-
:properties => {
|
23
|
-
:title => $client.version_support.text(analyzer: "standard", term_vector: "with_positions_offsets"),
|
24
|
-
:author => $client.version_support.keyword
|
25
|
-
}
|
13
|
+
settings: { "index.number_of_shards" => 1, "index.number_of_replicas" => 0 },
|
14
|
+
mappings: mappings_wrapper("book", {
|
15
|
+
_source: { enabled: true },
|
16
|
+
properties: {
|
17
|
+
title: { type: "text", analyzer: "standard", term_vector: "with_positions_offsets" },
|
18
|
+
author: { type: "keyword" }
|
26
19
|
}
|
27
|
-
}
|
20
|
+
}, true)
|
28
21
|
|
29
22
|
# COMPATIBILITY
|
30
|
-
if
|
31
|
-
@index.update_mapping("percolator", { :
|
23
|
+
if !$client.version_support.es_version_8_plus?
|
24
|
+
@index.update_mapping("percolator", { properties: { query: { type: "percolator"}}})
|
32
25
|
end
|
33
26
|
|
34
27
|
wait_for_index(@name)
|
@@ -42,56 +35,54 @@ describe Elastomer::Client::Docs do
|
|
42
35
|
end
|
43
36
|
|
44
37
|
it "raises error when writing same document twice" do
|
45
|
-
document = {
|
46
|
-
:
|
47
|
-
:
|
48
|
-
:
|
49
|
-
:
|
50
|
-
:
|
51
|
-
}
|
38
|
+
document = ({
|
39
|
+
_id: "documentid",
|
40
|
+
_type: "book",
|
41
|
+
_op_type: "create",
|
42
|
+
title: "Book by Author1",
|
43
|
+
author: "Author1"
|
44
|
+
})
|
52
45
|
h = @docs.index document.dup
|
53
46
|
|
54
47
|
assert_created h
|
55
48
|
|
56
|
-
assert_raises(
|
49
|
+
assert_raises(ElastomerClient::Client::DocumentAlreadyExistsError) do
|
57
50
|
@docs.index document.dup
|
58
51
|
end
|
59
52
|
end
|
60
53
|
|
61
54
|
it "autogenerates IDs for documents" do
|
62
|
-
h = @docs.index
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
h = @docs.index \
|
71
|
-
:_id => nil,
|
72
|
-
:_type => "doc3",
|
73
|
-
:title => "the author of rubber-band",
|
74
|
-
:author => "grantr"
|
55
|
+
h = @docs.index(
|
56
|
+
{
|
57
|
+
_id: nil,
|
58
|
+
title: "Book1 by author 1",
|
59
|
+
author: "Author1",
|
60
|
+
_type: "book"
|
61
|
+
})
|
75
62
|
|
76
63
|
assert_created h
|
77
64
|
assert_match %r/^\S{20,22}$/, h["_id"]
|
78
65
|
|
79
|
-
h = @docs.index
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
66
|
+
h = @docs.index(
|
67
|
+
{
|
68
|
+
_id: nil,
|
69
|
+
title: "Book2 by author 2",
|
70
|
+
author: "Author2",
|
71
|
+
_type: "book"
|
72
|
+
})
|
84
73
|
|
85
74
|
assert_created h
|
86
75
|
assert_match %r/^\S{20,22}$/, h["_id"]
|
87
76
|
end
|
88
77
|
|
89
78
|
it "uses the provided document ID" do
|
90
|
-
h = @docs.index
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
79
|
+
h = @docs.index (
|
80
|
+
{
|
81
|
+
_id: 42,
|
82
|
+
_type: "book",
|
83
|
+
title: "Book1 by author 1",
|
84
|
+
author: "Author1"
|
85
|
+
})
|
95
86
|
|
96
87
|
assert_created h
|
97
88
|
assert_equal "42", h["_id"]
|
@@ -99,56 +90,66 @@ describe Elastomer::Client::Docs do
|
|
99
90
|
|
100
91
|
it "accepts JSON encoded document strings" do
|
101
92
|
h = @docs.index \
|
102
|
-
|
103
|
-
|
104
|
-
|
93
|
+
'{"author":"Author1", "title":"Book1 by author 1"}',
|
94
|
+
id: 42,
|
95
|
+
type: "book"
|
105
96
|
|
106
97
|
assert_created h
|
107
98
|
assert_equal "42", h["_id"]
|
108
|
-
|
109
|
-
h = @docs.index \
|
110
|
-
'{"author":"grantr", "title":"the author of rubber-band"}',
|
111
|
-
:type => "doc2"
|
112
|
-
|
113
|
-
assert_created h
|
114
|
-
assert_match %r/^\S{20,22}$/, h["_id"]
|
115
99
|
end
|
116
100
|
|
117
101
|
describe "indexing directive fields" do
|
102
|
+
before do
|
103
|
+
# Since we set dynamic: strict, adding the above doc to the index throws an error, so update the index to allow dynamic mapping
|
104
|
+
if !$client.version_support.es_version_8_plus?
|
105
|
+
@index.update_mapping "book", { book: { dynamic: "true" } }
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
after do
|
110
|
+
# Since we set dynamic: strict, adding the above doc to the index throws an error, so update the index to allow dynamic mapping
|
111
|
+
if !$client.version_support.es_version_8_plus?
|
112
|
+
@index.update_mapping "book", { book: { dynamic: "strict" } }
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
118
116
|
it "indexes fields that are not recognized as indexing directives" do
|
119
|
-
doc = {
|
117
|
+
doc = ({
|
120
118
|
_id: "12",
|
121
|
-
_type: "
|
122
|
-
title: "
|
123
|
-
author: "
|
119
|
+
_type: "book",
|
120
|
+
title: "Book1",
|
121
|
+
author: "Author1",
|
124
122
|
_unknown_1: "unknown attribute 1",
|
125
|
-
"_unknown_2"
|
126
|
-
}
|
123
|
+
"_unknown_2": "unknown attribute 2"
|
124
|
+
})
|
127
125
|
|
128
126
|
h = @docs.index(doc)
|
127
|
+
|
129
128
|
assert_created h
|
130
129
|
assert_equal "12", h["_id"]
|
131
130
|
|
132
|
-
indexed_doc = @docs.get(type: "
|
131
|
+
indexed_doc = $client.version_support.es_version_8_plus? ? @docs.get(id: "12") : @docs.get(type: "book", id: "12")
|
133
132
|
expected = {
|
134
|
-
"title" => "
|
135
|
-
"author" => "
|
133
|
+
"title" => "Book1",
|
134
|
+
"author" => "Author1",
|
136
135
|
"_unknown_1" => "unknown attribute 1",
|
137
136
|
"_unknown_2" => "unknown attribute 2"
|
138
137
|
}
|
138
|
+
|
139
139
|
assert_equal expected, indexed_doc["_source"]
|
140
140
|
end
|
141
141
|
|
142
142
|
it "extracts indexing directives from the document" do
|
143
143
|
doc = {
|
144
144
|
_id: "12",
|
145
|
-
|
145
|
+
_type: "book",
|
146
146
|
_routing: "author",
|
147
|
-
title: "
|
148
|
-
author: "
|
147
|
+
title: "Book1",
|
148
|
+
author: "Author1"
|
149
149
|
}
|
150
150
|
|
151
151
|
h = @docs.index(doc)
|
152
|
+
|
152
153
|
assert_created h
|
153
154
|
assert_equal "12", h["_id"]
|
154
155
|
|
@@ -157,78 +158,87 @@ describe Elastomer::Client::Docs do
|
|
157
158
|
refute doc.key?("_type")
|
158
159
|
refute doc.key?(:_routing)
|
159
160
|
|
160
|
-
indexed_doc = @docs.get(type: "
|
161
|
+
indexed_doc = $client.version_support.es_version_8_plus? ? @docs.get(id: "12") : @docs.get(type: "book", id: "12")
|
161
162
|
expected = {
|
162
|
-
"title" => "
|
163
|
-
"author" => "
|
163
|
+
"title" => "Book1",
|
164
|
+
"author" => "Author1"
|
164
165
|
}
|
166
|
+
|
165
167
|
assert_equal expected, indexed_doc["_source"]
|
166
168
|
end
|
167
169
|
|
168
|
-
# COMPATIBILITY: Fail fast on known indexing directives that aren't for this version of ES
|
169
170
|
it "raises an exception when a known indexing directive from an unsupported version is used" do
|
170
171
|
# Symbol keys
|
171
|
-
doc = {
|
172
|
+
doc = ({
|
172
173
|
_id: "12",
|
173
|
-
_type: "
|
174
|
-
title: "
|
175
|
-
|
174
|
+
_type: "book",
|
175
|
+
title: "Book1",
|
176
|
+
_consistency: "all"
|
177
|
+
})
|
176
178
|
|
177
|
-
assert_raises(
|
179
|
+
assert_raises(ElastomerClient::Client::IllegalArgument) do
|
178
180
|
@docs.index(doc)
|
179
181
|
end
|
180
182
|
|
181
183
|
# String keys
|
182
|
-
doc = {
|
184
|
+
doc = ({
|
183
185
|
"_id" => "12",
|
184
|
-
"_type" => "
|
185
|
-
"title" => "
|
186
|
-
|
186
|
+
"_type" => "book",
|
187
|
+
"title" => "Book1",
|
188
|
+
"_consistency" => "all"
|
189
|
+
})
|
187
190
|
|
188
|
-
assert_raises(
|
191
|
+
assert_raises(ElastomerClient::Client::IllegalArgument) do
|
189
192
|
@docs.index(doc)
|
190
193
|
end
|
191
194
|
end
|
192
195
|
end
|
193
196
|
|
194
197
|
it "gets documents from the search index" do
|
195
|
-
h = @docs.get :id
|
198
|
+
h = $client.version_support.es_version_8_plus? ? @docs.get(id: "1") : @docs.get(id: "1", type: "book")
|
199
|
+
|
196
200
|
refute_found h
|
197
201
|
|
198
202
|
populate!
|
199
203
|
|
200
|
-
h = @docs.get :id
|
204
|
+
h = $client.version_support.es_version_8_plus? ? @docs.get(id: "1") : @docs.get(id: "1", type: "book")
|
205
|
+
|
201
206
|
assert_found h
|
202
|
-
assert_equal "
|
207
|
+
assert_equal "Author1", h["_source"]["author"]
|
203
208
|
end
|
204
209
|
|
205
210
|
it "checks if documents exist in the search index" do
|
206
|
-
refute @docs.exists?(:id
|
211
|
+
refute $client.version_support.es_version_8_plus? ? @docs.exists?(id: "1") : @docs.exists?(id: "1", type: "book")
|
207
212
|
populate!
|
208
|
-
|
213
|
+
|
214
|
+
assert $client.version_support.es_version_8_plus? ? @docs.exists?(id: "1") : @docs.exists?(id: "1", type: "book")
|
209
215
|
end
|
210
216
|
|
211
217
|
it "checks if documents exist in the search index with .exist?" do
|
212
|
-
refute @docs.exist?(:id
|
218
|
+
refute $client.version_support.es_version_8_plus? ? @docs.exist?(id: "1") : @docs.exist?(id: "1", type: "book")
|
213
219
|
populate!
|
214
|
-
|
220
|
+
|
221
|
+
assert $client.version_support.es_version_8_plus? ? @docs.exist?(id: "1") : @docs.exist?(id: "1", type: "book")
|
215
222
|
end
|
216
223
|
|
217
224
|
it "gets multiple documents from the search index" do
|
218
225
|
populate!
|
219
226
|
|
220
|
-
h = @docs.multi_get :
|
221
|
-
{ :
|
222
|
-
{
|
227
|
+
h = @docs.multi_get docs: [
|
228
|
+
document_wrapper("book", { _id: 1 }),
|
229
|
+
document_wrapper("book", { _id: 2 })
|
223
230
|
]
|
224
231
|
authors = h["docs"].map { |d| d["_source"]["author"] }
|
225
|
-
assert_equal %w[mojombo pea53], authors
|
226
232
|
|
227
|
-
|
233
|
+
assert_equal %w[Author1 Author2], authors
|
234
|
+
|
235
|
+
h = $client.version_support.es_version_8_plus? ? @docs.multi_get({ids: [2, 1]}) : @docs.multi_get({ids: [2, 1]}, type: "book")
|
228
236
|
authors = h["docs"].map { |d| d["_source"]["author"] }
|
229
|
-
assert_equal %w[defunkt mojombo], authors
|
230
237
|
|
231
|
-
|
238
|
+
assert_equal %w[Author2 Author1], authors
|
239
|
+
|
240
|
+
h = @index.docs("book").multi_get ids: [1, 2, 3, 4]
|
241
|
+
|
232
242
|
assert_found h["docs"][0]
|
233
243
|
assert_found h["docs"][1]
|
234
244
|
refute_found h["docs"][2]
|
@@ -238,18 +248,21 @@ describe Elastomer::Client::Docs do
|
|
238
248
|
it "gets multiple documents from the search index with .mget" do
|
239
249
|
populate!
|
240
250
|
|
241
|
-
h = @docs.mget :
|
242
|
-
{ :
|
243
|
-
{
|
251
|
+
h = @docs.mget docs: [
|
252
|
+
document_wrapper("book", { _id: 1 }),
|
253
|
+
document_wrapper("book", { _id: 2 })
|
244
254
|
]
|
245
255
|
authors = h["docs"].map { |d| d["_source"]["author"] }
|
246
|
-
assert_equal %w[mojombo pea53], authors
|
247
256
|
|
248
|
-
|
257
|
+
assert_equal %w[Author1 Author2], authors
|
258
|
+
|
259
|
+
h = @docs.mget({ids: [2, 1]})
|
249
260
|
authors = h["docs"].map { |d| d["_source"]["author"] }
|
250
|
-
assert_equal %w[defunkt mojombo], authors
|
251
261
|
|
252
|
-
|
262
|
+
assert_equal %w[Author2 Author1], authors
|
263
|
+
|
264
|
+
h = @index.docs("book").mget ids: [1, 2, 3, 4]
|
265
|
+
|
253
266
|
assert_found h["docs"][0]
|
254
267
|
assert_found h["docs"][1]
|
255
268
|
refute_found h["docs"][2]
|
@@ -258,184 +271,246 @@ describe Elastomer::Client::Docs do
|
|
258
271
|
|
259
272
|
it "deletes documents from the search index" do
|
260
273
|
populate!
|
261
|
-
@docs = @index.docs("
|
274
|
+
@docs = @index.docs("book")
|
262
275
|
|
263
|
-
h = @docs.multi_get :
|
276
|
+
h = @docs.multi_get ids: [1, 2]
|
264
277
|
authors = h["docs"].map { |d| d["_source"]["author"] }
|
265
|
-
assert_equal %w[pea53 grantr], authors
|
266
278
|
|
267
|
-
|
268
|
-
|
269
|
-
h = @docs.
|
279
|
+
assert_equal %w[Author1 Author2], authors
|
280
|
+
|
281
|
+
h = @docs.delete id: 1
|
282
|
+
|
283
|
+
if $client.version_support.es_version_8_plus?
|
284
|
+
assert_equal "deleted", h["result"], "expected document to be found"
|
285
|
+
else
|
286
|
+
assert h["found"], "expected document to be found"
|
287
|
+
end
|
288
|
+
|
289
|
+
h = @docs.multi_get ids: [1, 2]
|
290
|
+
|
270
291
|
refute_found h["docs"][0]
|
271
292
|
assert_found h["docs"][1]
|
272
293
|
|
273
|
-
assert_raises(ArgumentError) { @docs.delete :
|
274
|
-
assert_raises(ArgumentError) { @docs.delete :
|
275
|
-
assert_raises(ArgumentError) { @docs.delete :
|
294
|
+
assert_raises(ArgumentError) { @docs.delete id: nil }
|
295
|
+
assert_raises(ArgumentError) { @docs.delete id: "" }
|
296
|
+
assert_raises(ArgumentError) { @docs.delete id: "\t" }
|
276
297
|
end
|
277
298
|
|
278
299
|
it "does not care if you delete a document that is not there" do
|
279
|
-
@docs = @index.docs("
|
280
|
-
h = @docs.delete :
|
300
|
+
@docs = @index.docs("book")
|
301
|
+
h = @docs.delete id: 42
|
281
302
|
|
282
|
-
|
303
|
+
if $client.version_support.es_version_8_plus?
|
304
|
+
refute_equal "deleted", h["result"], "expected document to not be found"
|
305
|
+
else
|
306
|
+
refute h["found"], "expected document to not be found"
|
307
|
+
end
|
283
308
|
end
|
284
309
|
|
285
310
|
it "deletes documents by query" do
|
286
311
|
populate!
|
287
|
-
@docs = @index.docs("
|
312
|
+
@docs = @index.docs("book")
|
288
313
|
|
289
|
-
h = @docs.multi_get :
|
314
|
+
h = @docs.multi_get ids: [1, 2]
|
290
315
|
authors = h["docs"].map { |d| d["_source"]["author"] }
|
291
|
-
assert_equal %w[pea53 grantr], authors
|
292
316
|
|
293
|
-
|
317
|
+
assert_equal %w[Author1 Author2], authors
|
294
318
|
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
assert_equal(h["_indices"], {
|
299
|
-
"_all" => {
|
300
|
-
"found" => 1,
|
301
|
-
"deleted" => 1,
|
302
|
-
"missing" => 0,
|
303
|
-
"failed" => 0,
|
304
|
-
},
|
305
|
-
@name => {
|
306
|
-
"found" => 1,
|
307
|
-
"deleted" => 1,
|
308
|
-
"missing" => 0,
|
309
|
-
"failed" => 0,
|
310
|
-
},
|
311
|
-
})
|
312
|
-
end
|
319
|
+
h = @docs.delete_by_query(q: "author:Author2")
|
320
|
+
|
321
|
+
assert_equal(1, h["deleted"])
|
313
322
|
|
314
323
|
@index.refresh
|
315
|
-
h = @docs.multi_get :
|
324
|
+
h = @docs.multi_get ids: [1, 2]
|
325
|
+
|
316
326
|
assert_found h["docs"][0]
|
317
327
|
refute_found h["docs"][1]
|
318
328
|
|
319
329
|
h = @docs.delete_by_query(
|
320
|
-
:
|
321
|
-
:
|
322
|
-
:
|
330
|
+
query: {
|
331
|
+
bool: {
|
332
|
+
filter: {term: {author: "Author1"}}
|
323
333
|
}
|
324
334
|
}
|
325
335
|
)
|
326
336
|
@index.refresh
|
327
|
-
h = @docs.multi_get :
|
337
|
+
h = @docs.multi_get ids: [1, 2]
|
338
|
+
|
328
339
|
refute_found h["docs"][0]
|
329
340
|
refute_found h["docs"][1]
|
330
341
|
end
|
331
342
|
|
343
|
+
it "updates documents by query" do
|
344
|
+
populate!
|
345
|
+
|
346
|
+
r = @docs.update_by_query(query: {
|
347
|
+
bool: {
|
348
|
+
filter: {term: {author: "Author1"}}
|
349
|
+
}
|
350
|
+
}, script: {
|
351
|
+
source: "ctx._source.author = 'Author1 Updated'"
|
352
|
+
})
|
353
|
+
|
354
|
+
assert_equal 1, r["updated"]
|
355
|
+
|
356
|
+
r = @docs.update_by_query({
|
357
|
+
query: {
|
358
|
+
bool: {
|
359
|
+
filter: {term: {author: "Author2"}}
|
360
|
+
}
|
361
|
+
},
|
362
|
+
script: {
|
363
|
+
source: "ctx._source.author = 'Author2 Updated'"
|
364
|
+
}
|
365
|
+
}, conflicts: "proceed")
|
366
|
+
|
367
|
+
assert_equal 1, r["updated"]
|
368
|
+
|
369
|
+
@index.refresh
|
370
|
+
|
371
|
+
h = @docs.multi_get ids: [1, 2]
|
372
|
+
|
373
|
+
assert_equal "Author1 Updated", h["docs"][0]["_source"]["author"]
|
374
|
+
assert_equal "Author2 Updated", h["docs"][1]["_source"]["author"]
|
375
|
+
|
376
|
+
end
|
377
|
+
|
332
378
|
it "searches for documents" do
|
333
|
-
h = @docs.search :
|
334
|
-
|
379
|
+
h = @docs.search q: "*:*"
|
380
|
+
|
381
|
+
if $client.version_support.es_version_8_plus?
|
382
|
+
assert_equal 0, h["hits"]["total"]["value"]
|
383
|
+
else
|
384
|
+
assert_equal 0, h["hits"]["total"]
|
385
|
+
end
|
335
386
|
|
336
387
|
populate!
|
337
388
|
|
338
|
-
h = @docs.search :
|
339
|
-
assert_equal 4, h["hits"]["total"]
|
389
|
+
h = @docs.search q: "*:*"
|
340
390
|
|
341
|
-
|
342
|
-
|
391
|
+
if $client.version_support.es_version_8_plus?
|
392
|
+
assert_equal 2, h["hits"]["total"]["value"]
|
393
|
+
else
|
394
|
+
assert_equal 2, h["hits"]["total"]
|
395
|
+
end
|
396
|
+
|
397
|
+
if !$client.version_support.es_version_8_plus?
|
398
|
+
h = @docs.search q: "*:*", type: "book"
|
399
|
+
|
400
|
+
assert_equal 2, h["hits"]["total"]
|
401
|
+
end
|
343
402
|
|
344
403
|
h = @docs.search({
|
345
|
-
:
|
346
|
-
:
|
347
|
-
}
|
348
|
-
|
404
|
+
query: {match_all: {}},
|
405
|
+
post_filter: {term: {author: "Author1"}}
|
406
|
+
})
|
407
|
+
|
408
|
+
if $client.version_support.es_version_8_plus?
|
409
|
+
assert_equal 1, h["hits"]["total"]["value"]
|
410
|
+
else
|
411
|
+
assert_equal 1, h["hits"]["total"]
|
412
|
+
end
|
349
413
|
|
350
414
|
hit = h["hits"]["hits"].first
|
351
|
-
|
415
|
+
|
416
|
+
assert_equal "Book1 by author 1", hit["_source"]["title"]
|
352
417
|
end
|
353
418
|
|
354
419
|
it "supports the shards search API" do
|
355
|
-
h = @docs.search_shards(
|
420
|
+
h = @docs.search_shards(params={})
|
356
421
|
|
357
422
|
assert h.key?("nodes"), "response contains \"nodes\" information"
|
358
423
|
assert h.key?("shards"), "response contains \"shards\" information"
|
359
|
-
|
424
|
+
assert_kind_of Array, h["shards"], "\"shards\" is an array"
|
360
425
|
end
|
361
426
|
|
362
427
|
it "generates QueryParsingError exceptions on bad input when searching" do
|
363
|
-
query = {:
|
364
|
-
assert_raises(
|
428
|
+
query = {query: {query_string: {query: "OR should fail"}}}
|
429
|
+
assert_raises(ElastomerClient::Client::QueryParsingError) { @docs.search(query) }
|
365
430
|
|
366
|
-
query = {:
|
367
|
-
assert_raises(
|
431
|
+
query = {query: {foo_is_not_valid: {}}}
|
432
|
+
assert_raises(ElastomerClient::Client::QueryParsingError) { @docs.search(query) }
|
368
433
|
end
|
369
434
|
|
370
435
|
it "counts documents" do
|
371
|
-
h = @docs.count :
|
436
|
+
h = @docs.count q: "*:*"
|
437
|
+
|
372
438
|
assert_equal 0, h["count"]
|
373
439
|
|
374
440
|
populate!
|
375
441
|
|
376
|
-
h = @docs.count :
|
377
|
-
assert_equal 4, h["count"]
|
442
|
+
h = @docs.count q: "*:*"
|
378
443
|
|
379
|
-
h = @docs.count :q => "*:*", :type => "doc1"
|
380
444
|
assert_equal 2, h["count"]
|
381
445
|
|
382
|
-
|
383
|
-
|
446
|
+
if !$client.version_support.es_version_8_plus?
|
447
|
+
h = @docs.count(q: "*:*", type: "book")
|
448
|
+
|
449
|
+
assert_equal 2, h["count"]
|
450
|
+
end
|
384
451
|
|
385
452
|
h = @docs.count({
|
386
|
-
:
|
387
|
-
:
|
388
|
-
:
|
453
|
+
query: {
|
454
|
+
bool: {
|
455
|
+
filter: {term: {author: "Author1"}}
|
389
456
|
}
|
390
457
|
}
|
391
|
-
}
|
458
|
+
})
|
459
|
+
|
392
460
|
assert_equal 1, h["count"]
|
393
461
|
end
|
394
462
|
|
395
463
|
it "explains scoring" do
|
396
464
|
populate!
|
397
465
|
|
398
|
-
h =
|
399
|
-
|
400
|
-
:
|
401
|
-
|
466
|
+
h = $client.version_support.es_version_8_plus? ?
|
467
|
+
@docs.explain({
|
468
|
+
query: {
|
469
|
+
match: {
|
470
|
+
"author" => "Author1"
|
471
|
+
}
|
402
472
|
}
|
403
|
-
}
|
404
|
-
|
405
|
-
|
473
|
+
}, id: 1)
|
474
|
+
: @docs.explain({
|
475
|
+
query: {
|
476
|
+
match: {
|
477
|
+
"author" => "Author1"
|
478
|
+
}
|
479
|
+
}
|
480
|
+
}, id: 1, type: "book")
|
406
481
|
|
407
|
-
h
|
408
|
-
|
482
|
+
assert h["matched"]
|
483
|
+
|
484
|
+
h = $client.version_support.es_version_8_plus? ? @docs.explain(id: 2, q: "Author1") : @docs.explain(type: "book", id: 2, q: "Author1")
|
485
|
+
|
486
|
+
refute h["matched"]
|
409
487
|
end
|
410
488
|
|
411
489
|
it "validates queries" do
|
412
490
|
populate!
|
413
491
|
|
414
|
-
h = @docs.validate :
|
415
|
-
|
492
|
+
h = @docs.validate q: "*:*"
|
493
|
+
|
494
|
+
assert h["valid"]
|
416
495
|
|
417
496
|
h = @docs.validate({
|
418
|
-
:
|
419
|
-
:
|
420
|
-
:
|
421
|
-
:
|
497
|
+
query: {
|
498
|
+
filtered: {
|
499
|
+
query: {match_all: {}},
|
500
|
+
filter: {term: {author: "Author2"}}
|
422
501
|
}
|
423
502
|
}
|
424
|
-
}
|
503
|
+
})
|
425
504
|
|
426
|
-
|
427
|
-
refute h["valid"]
|
428
|
-
else
|
429
|
-
assert h["valid"]
|
430
|
-
end
|
505
|
+
refute h["valid"]
|
431
506
|
|
432
507
|
h = @docs.validate({
|
433
|
-
:
|
434
|
-
:
|
435
|
-
:
|
508
|
+
query: {
|
509
|
+
bool: {
|
510
|
+
filter: {term: {author: "Author2"}}
|
436
511
|
}
|
437
512
|
}
|
438
|
-
}
|
513
|
+
})
|
439
514
|
|
440
515
|
assert h["valid"]
|
441
516
|
end
|
@@ -443,97 +518,99 @@ describe Elastomer::Client::Docs do
|
|
443
518
|
it "updates documents" do
|
444
519
|
populate!
|
445
520
|
|
446
|
-
h = @docs.get :id
|
521
|
+
h = $client.version_support.es_version_8_plus? ? @docs.get(id: "1") : @docs.get(id: "1", type: "book")
|
522
|
+
|
447
523
|
assert_found h
|
448
|
-
assert_equal "
|
524
|
+
assert_equal "Author1", h["_source"]["author"]
|
525
|
+
|
526
|
+
@docs.update(document_wrapper("book", {
|
527
|
+
_id: "1",
|
528
|
+
doc: {author: "Author1.1"}
|
529
|
+
}))
|
530
|
+
h = $client.version_support.es_version_8_plus? ? @docs.get(id: "1") : @docs.get(id: "1", type: "book")
|
449
531
|
|
450
|
-
@docs.update({
|
451
|
-
:_id => "1",
|
452
|
-
:_type => "doc1",
|
453
|
-
:doc => {:author => "TwP"}
|
454
|
-
})
|
455
|
-
h = @docs.get :id => "1", :type => "doc1"
|
456
532
|
assert_found h
|
457
|
-
assert_equal "
|
533
|
+
assert_equal "Author1.1", h["_source"]["author"]
|
458
534
|
|
459
535
|
if $client.version >= "0.90"
|
460
|
-
@docs.update({
|
461
|
-
:
|
462
|
-
:
|
463
|
-
|
464
|
-
:
|
465
|
-
:title => "the ineffable beauty of search"
|
536
|
+
@docs.update(document_wrapper("book", {
|
537
|
+
_id: "42",
|
538
|
+
doc: {
|
539
|
+
author: "Author42",
|
540
|
+
title: "Book42"
|
466
541
|
},
|
467
|
-
:
|
468
|
-
})
|
542
|
+
doc_as_upsert: true
|
543
|
+
}))
|
544
|
+
|
545
|
+
h = $client.version_support.es_version_8_plus? ? @docs.get(id: "42") : @docs.get(id: "42", type: "book")
|
469
546
|
|
470
|
-
h = @docs.get :id => "42", :type => "doc1"
|
471
547
|
assert_found h
|
472
|
-
assert_equal "
|
473
|
-
assert_equal "
|
548
|
+
assert_equal "Author42", h["_source"]["author"]
|
549
|
+
assert_equal "Book42", h["_source"]["title"]
|
474
550
|
end
|
475
551
|
end
|
476
552
|
|
477
553
|
it "supports bulk operations with the same parameters as docs" do
|
478
554
|
response = @docs.bulk do |b|
|
479
|
-
|
555
|
+
populate_with_params!(b)
|
480
556
|
end
|
481
557
|
|
482
558
|
assert_kind_of Integer, response["took"]
|
483
559
|
|
484
|
-
response = @docs.get(:id
|
560
|
+
response = $client.version_support.es_version_8_plus? ? @docs.get(id: 1) : @docs.get(id: 1, type: "book")
|
561
|
+
|
485
562
|
assert_found response
|
486
|
-
assert_equal "
|
563
|
+
assert_equal "Author1", response["_source"]["author"]
|
487
564
|
end
|
488
565
|
|
489
566
|
it "provides access to term vector statistics" do
|
490
567
|
populate!
|
491
568
|
|
492
|
-
response = @docs.termvector :type
|
569
|
+
response = $client.version_support.es_version_8_plus? ? @docs.termvector(id: 1, fields: "title") : @docs.termvector(type: "book", id: 1, fields: "title")
|
493
570
|
|
494
571
|
assert response["term_vectors"]["title"]
|
495
572
|
assert response["term_vectors"]["title"]["field_statistics"]
|
496
573
|
assert response["term_vectors"]["title"]["terms"]
|
497
|
-
assert_equal %w[author
|
574
|
+
assert_equal %w[1 author book1 by], response["term_vectors"]["title"]["terms"].keys
|
498
575
|
end
|
499
576
|
|
500
577
|
it "provides access to term vector statistics with .termvectors" do
|
501
578
|
populate!
|
502
579
|
|
503
|
-
response = @docs.termvectors :type
|
580
|
+
response = $client.version_support.es_version_8_plus? ? @docs.termvectors(id: 1, fields: "title") : @docs.termvectors(type: "book", id: 1, fields: "title")
|
504
581
|
|
505
582
|
assert response["term_vectors"]["title"]
|
506
583
|
assert response["term_vectors"]["title"]["field_statistics"]
|
507
584
|
assert response["term_vectors"]["title"]["terms"]
|
508
|
-
assert_equal %w[author
|
585
|
+
assert_equal %w[1 author book1 by], response["term_vectors"]["title"]["terms"].keys
|
509
586
|
end
|
510
587
|
|
511
588
|
it "provides access to term vector statistics with .term_vector" do
|
512
589
|
populate!
|
513
590
|
|
514
|
-
response = @docs.term_vector :type
|
591
|
+
response = $client.version_support.es_version_8_plus? ? @docs.term_vector(id: 1, fields: "title") : @docs.term_vector(type: "book", id: 1, fields: "title")
|
515
592
|
|
516
593
|
assert response["term_vectors"]["title"]
|
517
594
|
assert response["term_vectors"]["title"]["field_statistics"]
|
518
595
|
assert response["term_vectors"]["title"]["terms"]
|
519
|
-
assert_equal %w[author
|
596
|
+
assert_equal %w[1 author book1 by], response["term_vectors"]["title"]["terms"].keys
|
520
597
|
end
|
521
598
|
|
522
599
|
it "provides access to term vector statistics with .term_vectors" do
|
523
600
|
populate!
|
524
601
|
|
525
|
-
response = @docs.term_vectors :type
|
602
|
+
response = $client.version_support.es_version_8_plus? ? @docs.term_vectors(id: 1, fields: "title") : @docs.term_vectors(type: "book", id: 1, fields: "title")
|
526
603
|
|
527
604
|
assert response["term_vectors"]["title"]
|
528
605
|
assert response["term_vectors"]["title"]["field_statistics"]
|
529
606
|
assert response["term_vectors"]["title"]["terms"]
|
530
|
-
assert_equal %w[author
|
607
|
+
assert_equal %w[1 author book1 by], response["term_vectors"]["title"]["terms"].keys
|
531
608
|
end
|
532
609
|
|
533
610
|
it "provides access to multi term vector statistics" do
|
534
611
|
populate!
|
535
612
|
|
536
|
-
response = @docs.multi_termvectors({:
|
613
|
+
response = $client.version_support.es_version_8_plus? ? @docs.multi_termvectors({ids: [1, 2]}, fields: "title", term_statistics: true) : @docs.multi_termvectors({ids: [1, 2]}, type: "book", fields: "title", term_statistics: true)
|
537
614
|
docs = response["docs"]
|
538
615
|
|
539
616
|
assert docs
|
@@ -543,7 +620,7 @@ describe Elastomer::Client::Docs do
|
|
543
620
|
it "provides access to multi term vector statistics with .multi_term_vectors" do
|
544
621
|
populate!
|
545
622
|
|
546
|
-
response = @docs.multi_term_vectors({:
|
623
|
+
response = $client.version_support.es_version_8_plus? ? @docs.multi_term_vectors({ids: [1, 2]}, fields: "title", term_statistics: true) : @docs.multi_term_vectors({ids: [1, 2]}, type: "book", fields: "title", term_statistics: true)
|
547
624
|
docs = response["docs"]
|
548
625
|
|
549
626
|
assert docs
|
@@ -551,79 +628,112 @@ describe Elastomer::Client::Docs do
|
|
551
628
|
end
|
552
629
|
|
553
630
|
it "percolates a given document" do
|
631
|
+
if $client.version_support.es_version_8_plus?
|
632
|
+
skip "Percolate not supported in ES version #{$client.version}"
|
633
|
+
end
|
634
|
+
|
554
635
|
populate!
|
555
636
|
|
556
637
|
percolator1 = @index.percolator "1"
|
557
|
-
response = percolator1.create :
|
638
|
+
response = percolator1.create query: { match: { author: "Author1" } }
|
639
|
+
|
558
640
|
assert response["created"], "Couldn't create the percolator query"
|
559
641
|
percolator2 = @index.percolator "2"
|
560
|
-
response = percolator2.create :
|
642
|
+
response = percolator2.create query: { match: { author: "Author2" } }
|
643
|
+
|
561
644
|
assert response["created"], "Couldn't create the percolator query"
|
562
645
|
@index.refresh
|
563
646
|
|
564
|
-
response = @index.docs("
|
647
|
+
response = @index.docs("book").percolate(doc: { author: "Author1" })
|
648
|
+
|
565
649
|
assert_equal 1, response["matches"].length
|
566
650
|
assert_equal "1", response["matches"][0]["_id"]
|
567
651
|
end
|
568
652
|
|
569
653
|
it "percolates an existing document" do
|
654
|
+
if $client.version_support.es_version_8_plus?
|
655
|
+
skip "Percolate not supported in ES version #{$client.version}"
|
656
|
+
end
|
657
|
+
|
570
658
|
populate!
|
571
659
|
|
572
660
|
percolator1 = @index.percolator "1"
|
573
|
-
response = percolator1.create :
|
661
|
+
response = percolator1.create query: { match: { author: "Author1" } }
|
662
|
+
|
574
663
|
assert response["created"], "Couldn't create the percolator query"
|
575
664
|
percolator2 = @index.percolator "2"
|
576
|
-
response = percolator2.create :
|
665
|
+
response = percolator2.create query: { match: { author: "Author2" } }
|
666
|
+
|
577
667
|
assert response["created"], "Couldn't create the percolator query"
|
578
668
|
@index.refresh
|
579
669
|
|
580
|
-
response = @index.docs("
|
670
|
+
response = @index.docs("book").percolate(nil, id: "1")
|
671
|
+
|
581
672
|
assert_equal 1, response["matches"].length
|
582
673
|
assert_equal "1", response["matches"][0]["_id"]
|
583
674
|
end
|
584
675
|
|
585
676
|
it "counts the matches for percolating a given document" do
|
677
|
+
if $client.version_support.es_version_8_plus?
|
678
|
+
skip "Percolate not supported in ES version #{$client.version}"
|
679
|
+
end
|
680
|
+
|
586
681
|
populate!
|
587
682
|
|
588
683
|
percolator1 = @index.percolator "1"
|
589
|
-
response = percolator1.create :
|
684
|
+
response = percolator1.create query: { match: { author: "Author1" } }
|
685
|
+
|
590
686
|
assert response["created"], "Couldn't create the percolator query"
|
591
687
|
percolator2 = @index.percolator "2"
|
592
|
-
response = percolator2.create :
|
688
|
+
response = percolator2.create query: { match: { author: "Author2" } }
|
689
|
+
|
593
690
|
assert response["created"], "Couldn't create the percolator query"
|
594
691
|
@index.refresh
|
595
692
|
|
596
|
-
count = @index.docs("
|
693
|
+
count = @index.docs("book").percolate_count doc: { author: "Author1" }
|
694
|
+
|
597
695
|
assert_equal 1, count
|
598
696
|
end
|
599
697
|
|
600
698
|
it "counts the matches for percolating an existing document" do
|
699
|
+
if $client.version_support.es_version_8_plus?
|
700
|
+
skip "Percolate not supported in ES version #{$client.version}"
|
701
|
+
end
|
702
|
+
|
601
703
|
populate!
|
602
704
|
|
603
705
|
percolator1 = @index.percolator "1"
|
604
|
-
response = percolator1.create :
|
706
|
+
response = percolator1.create query: { match: { author: "Author1" } }
|
707
|
+
|
605
708
|
assert response["created"], "Couldn't create the percolator query"
|
606
709
|
percolator2 = @index.percolator "2"
|
607
|
-
response = percolator2.create :
|
710
|
+
response = percolator2.create query: { match: { author: "Author2" } }
|
711
|
+
|
608
712
|
assert response["created"], "Couldn't create the percolator query"
|
609
713
|
@index.refresh
|
610
714
|
|
611
|
-
count = @index.docs("
|
715
|
+
count = @index.docs("book").percolate_count(nil, id: "1")
|
716
|
+
|
612
717
|
assert_equal 1, count
|
613
718
|
end
|
614
719
|
|
615
720
|
it "performs multi percolate queries" do
|
616
|
-
|
617
|
-
|
721
|
+
if $client.version_support.es_version_8_plus?
|
722
|
+
skip "Multi percolate not supported in ES version #{$client.version}"
|
723
|
+
end
|
724
|
+
|
725
|
+
@index.percolator("1").create query: { match_all: { } }
|
726
|
+
@index.percolator("2").create query: { match: { author: "Author1" } }
|
618
727
|
@index.refresh
|
619
728
|
|
620
|
-
h = @index.docs("
|
621
|
-
m.percolate :
|
622
|
-
m.percolate :
|
623
|
-
m.count({}, { :
|
729
|
+
h = @index.docs("book").multi_percolate do |m|
|
730
|
+
m.percolate author: "Author1"
|
731
|
+
m.percolate author: "Author2"
|
732
|
+
m.count({}, { author: "Author2" })
|
624
733
|
end
|
625
734
|
|
626
735
|
response1, response2, response3 = h["responses"]
|
736
|
+
|
627
737
|
assert_equal ["1", "2"], response1["matches"].map { |match| match["_id"] }.sort
|
628
738
|
assert_equal ["1"], response2["matches"].map { |match| match["_id"] }.sort
|
629
739
|
assert_equal 1, response3["total"]
|
@@ -631,33 +741,36 @@ describe Elastomer::Client::Docs do
|
|
631
741
|
|
632
742
|
# Create/index multiple documents.
|
633
743
|
#
|
634
|
-
# docs - An instance of
|
744
|
+
# docs - An instance of ElastomerClient::Client::Docs or ElastomerClient::Client::Bulk. If
|
635
745
|
# nil uses the @docs instance variable.
|
636
|
-
# rubocop:disable Metrics/MethodLength
|
637
746
|
def populate!(docs = @docs)
|
638
|
-
docs.index
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
docs.index
|
657
|
-
|
658
|
-
|
659
|
-
:
|
660
|
-
|
747
|
+
docs.index ({
|
748
|
+
_id: 1,
|
749
|
+
_type: "book",
|
750
|
+
title: "Book1 by author 1",
|
751
|
+
author: "Author1"
|
752
|
+
})
|
753
|
+
|
754
|
+
docs.index ({
|
755
|
+
_id: 2,
|
756
|
+
_type: "book",
|
757
|
+
title: "Book2 by author 2",
|
758
|
+
author: "Author2"
|
759
|
+
})
|
760
|
+
|
761
|
+
@index.refresh
|
762
|
+
end
|
763
|
+
|
764
|
+
def populate_with_params!(docs = @docs)
|
765
|
+
docs.index({
|
766
|
+
title: "Book1 by author 1",
|
767
|
+
author: "Author1"
|
768
|
+
}, { _id: 1, _type: "book" })
|
769
|
+
|
770
|
+
docs.index({
|
771
|
+
title: "Book2 by author 2",
|
772
|
+
author: "Author2"
|
773
|
+
}, { _id: 2, _type: "book" })
|
661
774
|
|
662
775
|
@index.refresh
|
663
776
|
end
|