elastomer-client 3.2.3 → 6.2.1
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 +76 -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 +34 -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 +100 -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/bulk_test.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative "../test_helper"
|
4
|
+
require "json"
|
2
5
|
|
3
|
-
describe
|
6
|
+
describe ElastomerClient::Client::Bulk do
|
4
7
|
|
5
8
|
before do
|
6
9
|
@name = "elastomer-bulk-test"
|
@@ -8,23 +11,14 @@ describe Elastomer::Client::Bulk do
|
|
8
11
|
|
9
12
|
unless @index.exists?
|
10
13
|
@index.create \
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:
|
14
|
-
|
15
|
-
:
|
16
|
-
|
17
|
-
:author => $client.version_support.keyword
|
18
|
-
}
|
19
|
-
},
|
20
|
-
:book => {
|
21
|
-
:_source => { :enabled => true }, :_all => { :enabled => false },
|
22
|
-
:properties => {
|
23
|
-
:title => $client.version_support.text(analyzer: "standard"),
|
24
|
-
:author => $client.version_support.keyword
|
25
|
-
}
|
14
|
+
settings: { "index.number_of_shards" => 1, "index.number_of_replicas" => 0 },
|
15
|
+
mappings: mappings_wrapper("book", {
|
16
|
+
_source: { enabled: true },
|
17
|
+
properties: {
|
18
|
+
title: { type: "text", analyzer: "standard" },
|
19
|
+
author: { type: "keyword" }
|
26
20
|
}
|
27
|
-
}
|
21
|
+
})
|
28
22
|
|
29
23
|
wait_for_index(@name)
|
30
24
|
end
|
@@ -36,10 +30,10 @@ describe Elastomer::Client::Bulk do
|
|
36
30
|
|
37
31
|
it "performs bulk index actions" do
|
38
32
|
body = [
|
39
|
-
|
40
|
-
'{"author":"
|
41
|
-
|
42
|
-
'{"author":"
|
33
|
+
{index: document_wrapper("book", {_id: "1", _index: "elastomer-bulk-test"})}.to_json,
|
34
|
+
'{"author":"Author 1", "title":"Book 1"}',
|
35
|
+
{index: document_wrapper("book", {_id: "2", _index: "elastomer-bulk-test"})}.to_json,
|
36
|
+
'{"author":"Author 2", "title":"Book 2"}',
|
43
37
|
nil
|
44
38
|
]
|
45
39
|
body = body.join "\n"
|
@@ -50,38 +44,42 @@ describe Elastomer::Client::Bulk do
|
|
50
44
|
|
51
45
|
@index.refresh
|
52
46
|
|
53
|
-
h = @index.docs("
|
54
|
-
|
47
|
+
h = @index.docs("book").get id: 1
|
48
|
+
|
49
|
+
assert_equal "Author 1", h["_source"]["author"]
|
55
50
|
|
56
|
-
h = @index.docs("book").get :
|
57
|
-
|
51
|
+
h = @index.docs("book").get id: 2
|
52
|
+
|
53
|
+
assert_equal "Author 2", h["_source"]["author"]
|
58
54
|
|
59
55
|
|
60
56
|
body = [
|
61
|
-
|
62
|
-
'{"author":"
|
63
|
-
|
57
|
+
{index: document_wrapper("book", {_id: "3"})}.to_json,
|
58
|
+
'{"author":"Author 3", "title":"Book 3"}',
|
59
|
+
{delete: document_wrapper("book", {_id: "1"})}.to_json,
|
64
60
|
nil
|
65
61
|
]
|
66
62
|
body = body.join "\n"
|
67
|
-
h = $client.bulk body, :
|
63
|
+
h = $client.bulk body, index: @name
|
68
64
|
|
69
65
|
assert_bulk_index h["items"].first, "expected to index a book"
|
70
66
|
assert_bulk_delete h["items"].last, "expected to delete a book"
|
71
67
|
|
72
68
|
@index.refresh
|
73
69
|
|
74
|
-
h = @index.docs("book").get :
|
75
|
-
|
70
|
+
h = @index.docs("book").get id: 1
|
71
|
+
|
72
|
+
refute h["exists"], "was not successfully deleted"
|
76
73
|
|
77
|
-
h = @index.docs("book").get :
|
78
|
-
|
74
|
+
h = @index.docs("book").get id: 3
|
75
|
+
|
76
|
+
assert_equal "Author 3", h["_source"]["author"]
|
79
77
|
end
|
80
78
|
|
81
79
|
it "supports a nice block syntax" do
|
82
80
|
h = @index.bulk do |b|
|
83
|
-
b.index :
|
84
|
-
b.index :
|
81
|
+
b.index({ author: "Author 1", title: "Book 1" }, { _id: 1, _type: "book" })
|
82
|
+
b.index({ author: "Author 2", title: "Book 2" }, { _id: nil, _type: "book" })
|
85
83
|
end
|
86
84
|
items = h["items"]
|
87
85
|
|
@@ -89,62 +87,52 @@ describe Elastomer::Client::Bulk do
|
|
89
87
|
|
90
88
|
assert_equal 2, h["items"].length
|
91
89
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
book_id = items.last["create"]["_id"]
|
96
|
-
else
|
97
|
-
assert_bulk_index h["items"].first
|
98
|
-
assert_bulk_index h["items"].last
|
99
|
-
book_id = items.last["index"]["_id"]
|
100
|
-
end
|
90
|
+
assert_bulk_index h["items"].first
|
91
|
+
assert_bulk_index h["items"].last
|
92
|
+
book_id = items.last["index"]["_id"]
|
101
93
|
|
102
94
|
assert_match %r/^\S{20,22}$/, book_id
|
103
95
|
|
104
96
|
@index.refresh
|
105
97
|
|
106
|
-
h = @index.docs("
|
107
|
-
|
98
|
+
h = @index.docs("book").get id: 1
|
99
|
+
|
100
|
+
assert_equal "Author 1", h["_source"]["author"]
|
108
101
|
|
109
|
-
h = @index.docs("book").get :
|
110
|
-
assert_equal "John Scalzi", h["_source"]["author"]
|
102
|
+
h = @index.docs("book").get id: book_id
|
111
103
|
|
104
|
+
assert_equal "Author 2", h["_source"]["author"]
|
112
105
|
|
113
106
|
h = @index.bulk do |b|
|
114
|
-
b.index
|
115
|
-
b.delete :
|
107
|
+
b.index({ author: "Author 3", title: "Book 3" }, _id: "", _type: "book")
|
108
|
+
b.delete ({_id: book_id, _type: "book"})
|
116
109
|
end
|
117
110
|
items = h["items"]
|
118
111
|
|
119
112
|
assert_equal 2, h["items"].length
|
120
113
|
|
121
|
-
|
122
|
-
|
123
|
-
assert_bulk_delete h["items"].last, "expected to delete a book"
|
124
|
-
|
125
|
-
book_id2 = items.first["create"]["_id"]
|
126
|
-
else
|
127
|
-
assert_bulk_index h["items"].first, "expected to create a book"
|
128
|
-
assert_bulk_delete h["items"].last, "expected to delete a book"
|
114
|
+
assert_bulk_index h["items"].first, "expected to create a book"
|
115
|
+
assert_bulk_delete h["items"].last, "expected to delete a book"
|
129
116
|
|
130
|
-
|
131
|
-
end
|
117
|
+
book_id2 = items.first["index"]["_id"]
|
132
118
|
|
133
119
|
assert_match %r/^\S{20,22}$/, book_id2
|
134
120
|
|
135
121
|
@index.refresh
|
136
122
|
|
137
|
-
h = @index.docs("book").get :
|
138
|
-
assert !h["exists"], "was not successfully deleted"
|
123
|
+
h = @index.docs("book").get id: book_id
|
139
124
|
|
140
|
-
h
|
141
|
-
|
125
|
+
refute h["exists"], "was not successfully deleted"
|
126
|
+
|
127
|
+
h = @index.docs("book").get id: book_id2
|
128
|
+
|
129
|
+
assert_equal "Author 3", h["_source"]["author"]
|
142
130
|
end
|
143
131
|
|
144
132
|
it "allows documents to be JSON strings" do
|
145
133
|
h = @index.bulk do |b|
|
146
|
-
b.index '{"author":"
|
147
|
-
b.create '{"author":"
|
134
|
+
b.index '{"author":"Author 1", "title":"Book 1"}', {_id: 1, _type: "book"}
|
135
|
+
b.create '{"author":"Author 2", "title":"Book 2"}', {_id: 2, _type: "book"}
|
148
136
|
end
|
149
137
|
|
150
138
|
assert_kind_of Integer, h["took"]
|
@@ -154,15 +142,17 @@ describe Elastomer::Client::Bulk do
|
|
154
142
|
|
155
143
|
@index.refresh
|
156
144
|
|
157
|
-
h = @index.docs("
|
158
|
-
|
145
|
+
h = @index.docs("book").get id: 1
|
146
|
+
|
147
|
+
assert_equal "Author 1", h["_source"]["author"]
|
148
|
+
|
149
|
+
h = @index.docs("book").get id: 2
|
159
150
|
|
160
|
-
|
161
|
-
assert_equal "John Scalzi", h["_source"]["author"]
|
151
|
+
assert_equal "Author 2", h["_source"]["author"]
|
162
152
|
|
163
153
|
h = @index.bulk do |b|
|
164
|
-
b.index '{"author":"
|
165
|
-
b.delete :
|
154
|
+
b.index '{"author":"Author 3", "title":"Book 3"}', {_id: 3, _type: "book"}
|
155
|
+
b.delete ({_id: 1, _type: "book"})
|
166
156
|
end
|
167
157
|
|
168
158
|
assert_bulk_index h["items"].first, "expected to index a book"
|
@@ -170,32 +160,39 @@ describe Elastomer::Client::Bulk do
|
|
170
160
|
|
171
161
|
@index.refresh
|
172
162
|
|
173
|
-
h = @index.docs("book").get :
|
174
|
-
assert !h["exists"], "was not successfully deleted"
|
163
|
+
h = @index.docs("book").get id: 1
|
175
164
|
|
176
|
-
h
|
177
|
-
|
165
|
+
refute h["exists"], "was not successfully deleted"
|
166
|
+
|
167
|
+
h = @index.docs("book").get id: 3
|
168
|
+
|
169
|
+
assert_equal "Author 3", h["_source"]["author"]
|
178
170
|
end
|
179
171
|
|
180
172
|
it "executes a bulk API call when a request size is reached" do
|
181
173
|
ary = []
|
182
|
-
|
174
|
+
# since ES8 does not include the mapping type in the document, it has less characters per request
|
175
|
+
# add characters to the document to get 100 characters per request
|
176
|
+
book_title = $client.version_support.es_version_8_plus? ? "A"*52 : "A"*34
|
177
|
+
ary << @index.bulk(request_size: 300) do |b|
|
183
178
|
2.times { |num|
|
184
|
-
document = {
|
185
|
-
ary << b.index(document)
|
179
|
+
document = { author: "Author 1", title: book_title}
|
180
|
+
ary << b.index(document, { _id: num, _type: "book" })
|
186
181
|
}
|
187
182
|
ary.compact!
|
183
|
+
|
188
184
|
assert_equal 0, ary.length
|
189
185
|
|
190
186
|
7.times { |num|
|
191
|
-
document = {
|
192
|
-
ary << b.index(document)
|
187
|
+
document = { author: "Author 1", title: book_title }
|
188
|
+
ary << b.index(document, { _id: num+2, _type: "book" })
|
193
189
|
}
|
194
190
|
ary.compact!
|
191
|
+
|
195
192
|
assert_equal 4, ary.length
|
196
193
|
|
197
|
-
document = {:
|
198
|
-
ary << b.index(document)
|
194
|
+
document = {author: "Author 1", title: book_title}
|
195
|
+
ary << b.index(document, {_id: 10, _type: "book"})
|
199
196
|
end
|
200
197
|
ary.compact!
|
201
198
|
|
@@ -203,30 +200,36 @@ describe Elastomer::Client::Bulk do
|
|
203
200
|
ary.each { |a| a["items"].each { |b| assert_bulk_index(b) } }
|
204
201
|
|
205
202
|
@index.refresh
|
206
|
-
h = @index.docs.search :
|
203
|
+
h = @index.docs.search q: "*:*", size: 0
|
207
204
|
|
208
|
-
|
205
|
+
if $client.version_support.es_version_8_plus?
|
206
|
+
assert_equal 10, h["hits"]["total"]["value"]
|
207
|
+
else
|
208
|
+
assert_equal 10, h["hits"]["total"]
|
209
|
+
end
|
209
210
|
end
|
210
211
|
|
211
212
|
it "executes a bulk API call when an action count is reached" do
|
212
213
|
ary = []
|
213
|
-
ary << @index.bulk(:
|
214
|
+
ary << @index.bulk(action_count: 3) do |b|
|
214
215
|
2.times { |num|
|
215
|
-
document = {:
|
216
|
-
ary << b.index(document)
|
216
|
+
document = {author: "Author 1", title: "This is book number #{num}"}
|
217
|
+
ary << b.index(document, {_id: num, _type: "book"})
|
217
218
|
}
|
218
219
|
ary.compact!
|
220
|
+
|
219
221
|
assert_equal 0, ary.length
|
220
222
|
|
221
223
|
7.times { |num|
|
222
|
-
document = {:
|
223
|
-
ary << b.index(document)
|
224
|
+
document = {author: "Author 1", title: "This is book number #{num+2}"}
|
225
|
+
ary << b.index(document, {_id: num+2, _type: "book"})
|
224
226
|
}
|
225
227
|
ary.compact!
|
228
|
+
|
226
229
|
assert_equal 2, ary.length
|
227
230
|
|
228
|
-
document = {:
|
229
|
-
ary << b.index(document)
|
231
|
+
document = {author: "Author 1", title: "This is book number 10"}
|
232
|
+
ary << b.index(document, {_id: 10, _type: "book"})
|
230
233
|
end
|
231
234
|
ary.compact!
|
232
235
|
|
@@ -234,26 +237,32 @@ describe Elastomer::Client::Bulk do
|
|
234
237
|
ary.each { |a| a["items"].each { |b| assert_bulk_index(b) } }
|
235
238
|
|
236
239
|
@index.refresh
|
237
|
-
h = @index.docs.search :
|
240
|
+
h = @index.docs.search q: "*:*", size: 0
|
238
241
|
|
239
|
-
|
242
|
+
if $client.version_support.es_version_8_plus?
|
243
|
+
assert_equal 10, h["hits"]["total"]["value"]
|
244
|
+
else
|
245
|
+
assert_equal 10, h["hits"]["total"]
|
246
|
+
end
|
240
247
|
end
|
241
248
|
|
242
|
-
it "rejects documents that
|
243
|
-
client =
|
249
|
+
it "rejects documents that exceed the maximum request size" do
|
250
|
+
client = ElastomerClient::Client.new(**$client_params.merge(max_request_size: 300))
|
244
251
|
index = client.index(@name)
|
245
252
|
|
246
253
|
ary = []
|
247
|
-
|
254
|
+
book_title = $client.version_support.es_version_8_plus? ? "A"*52 : "A"*34
|
255
|
+
ary << index.bulk(request_size: 300) do |b|
|
248
256
|
2.times { |num|
|
249
|
-
document = {:
|
250
|
-
ary << b.index(document)
|
257
|
+
document = {author: "Author 1", title: book_title}
|
258
|
+
ary << b.index(document, document_wrapper("book", { _id: num }))
|
251
259
|
}
|
252
260
|
ary.compact!
|
261
|
+
|
253
262
|
assert_equal 0, ary.length
|
254
263
|
|
255
|
-
document = {
|
256
|
-
assert_raises(
|
264
|
+
document = { author: "Author 1", message: "A"*290 }
|
265
|
+
assert_raises(ElastomerClient::Client::RequestSizeError) { b.index(document, document_wrapper("book", { _id: 342 })) }
|
257
266
|
end
|
258
267
|
ary.compact!
|
259
268
|
|
@@ -261,88 +270,103 @@ describe Elastomer::Client::Bulk do
|
|
261
270
|
ary.each { |a| a["items"].each { |b| assert_bulk_index(b) } }
|
262
271
|
|
263
272
|
index.refresh
|
264
|
-
h = index.docs.search :
|
273
|
+
h = index.docs.search q: "*:*", size: 0
|
265
274
|
|
266
|
-
|
275
|
+
if $client.version_support.es_version_8_plus?
|
276
|
+
assert_equal 2, h["hits"]["total"]["value"]
|
277
|
+
else
|
278
|
+
assert_equal 2, h["hits"]["total"]
|
279
|
+
end
|
267
280
|
end
|
268
281
|
|
269
|
-
it "uses :id from parameters" do
|
282
|
+
it "uses :id from parameters and supports symbol and string parameters" do
|
270
283
|
response = @index.bulk do |b|
|
271
|
-
|
272
|
-
|
284
|
+
document1 = { author: "Author 1", title: "Book 1" }
|
285
|
+
b.index document1, { id: "foo", type: "book" }
|
273
286
|
|
274
|
-
|
287
|
+
document2 = { author: "Author 2", title: "Book 2" }
|
288
|
+
b.index document2, { "id" => "bar", "type" => "book" }
|
275
289
|
end
|
276
290
|
|
277
291
|
assert_kind_of Integer, response["took"]
|
278
292
|
|
279
293
|
items = response["items"]
|
294
|
+
|
280
295
|
assert_bulk_index(items[0])
|
281
296
|
|
282
297
|
assert_equal "foo", items[0]["index"]["_id"]
|
298
|
+
assert_equal "Book 1", @index.docs("book").get(id: "foo")["_source"]["title"]
|
299
|
+
|
300
|
+
assert_equal "bar", items[1]["index"]["_id"]
|
301
|
+
assert_equal "Book 2", @index.docs("book").get(id: "bar")["_source"]["title"]
|
283
302
|
end
|
284
303
|
|
285
|
-
it "
|
304
|
+
it "empty symbol and string parameters don't set id" do
|
286
305
|
response = @index.bulk do |b|
|
287
|
-
|
288
|
-
b.index
|
306
|
+
document1 = { author: "Author 1", title: "Book 1" }
|
307
|
+
b.index document1, { id: "", type: "book" }
|
289
308
|
|
290
|
-
|
291
|
-
b.index
|
309
|
+
document2 = { author: "Author 2", title: "Book 2" }
|
310
|
+
b.index document2, { "id" => "", "type" => "book" }
|
292
311
|
end
|
293
312
|
|
294
313
|
assert_kind_of Integer, response["took"]
|
295
314
|
|
296
315
|
items = response["items"]
|
316
|
+
|
297
317
|
assert_bulk_index(items[0])
|
298
|
-
assert_bulk_index(items[1])
|
299
318
|
|
300
|
-
|
301
|
-
|
319
|
+
# ES will generate ids for these documents
|
320
|
+
id1 = items[0]["index"]["_id"]
|
321
|
+
id2 = items[1]["index"]["_id"]
|
322
|
+
|
323
|
+
assert_equal "Book 1", @index.docs("book").get(id: id1)["_source"]["title"]
|
324
|
+
assert_equal "Book 2", @index.docs("book").get(id: id2)["_source"]["title"]
|
302
325
|
end
|
303
326
|
|
304
|
-
it
|
305
|
-
document = { :
|
306
|
-
params = { :id => 2 }
|
327
|
+
it "supports the routing parameter on index actions" do
|
328
|
+
document = { title: "Book 1" }
|
307
329
|
|
308
330
|
response = @index.bulk do |b|
|
309
|
-
b.index document,
|
331
|
+
b.index document, { routing: "custom", _id: 1, _type: "book" }
|
310
332
|
end
|
311
333
|
|
312
|
-
assert_kind_of Integer, response["took"]
|
313
|
-
|
314
334
|
items = response["items"]
|
315
|
-
assert_bulk_index(items[0])
|
316
335
|
|
317
|
-
|
318
|
-
|
336
|
+
assert_kind_of Integer, response["took"]
|
337
|
+
assert_bulk_index(items[0])
|
338
|
+
assert_equal "custom", @index.docs("book").get(id: 1)["_routing"]
|
319
339
|
end
|
320
340
|
|
321
|
-
it
|
322
|
-
document = { :
|
323
|
-
|
341
|
+
it "supports the routing parameter within params in ES5 and ES8" do
|
342
|
+
document = { title: "Book 1" }
|
343
|
+
|
344
|
+
params = { _id: 1, _type: "book" }
|
345
|
+
if $client.version_support.es_version_8_plus?
|
346
|
+
params[:routing] = "custom"
|
347
|
+
else
|
348
|
+
params[:_routing] = "custom"
|
349
|
+
end
|
324
350
|
|
325
351
|
response = @index.bulk do |b|
|
326
352
|
b.index document, params
|
327
353
|
end
|
328
354
|
|
329
|
-
assert_kind_of Integer, response["took"]
|
330
|
-
|
331
355
|
items = response["items"]
|
332
|
-
assert_bulk_index(items[0])
|
333
356
|
|
334
|
-
|
335
|
-
|
336
|
-
assert_equal
|
357
|
+
assert_kind_of Integer, response["took"]
|
358
|
+
assert_bulk_index(items[0])
|
359
|
+
assert_equal "custom", @index.docs("book").get(id: 1)["_routing"]
|
337
360
|
end
|
338
361
|
|
339
362
|
it "streams bulk responses" do
|
340
363
|
ops = [
|
341
|
-
[:index, { :
|
342
|
-
[:index, { :
|
343
|
-
[:index, { :
|
364
|
+
[:index, { title: "Book 1" }, document_wrapper("book", { _id: 1, _index: @index.name })],
|
365
|
+
[:index, { title: "Book 2" }, document_wrapper("book", { _id: 2, _index: @index.name })],
|
366
|
+
[:index, { title: "Book 3" }, document_wrapper("book", { _id: 3, _index: @index.name })],
|
344
367
|
]
|
345
|
-
responses = $client.bulk_stream_responses(ops, { :
|
368
|
+
responses = $client.bulk_stream_responses(ops, { action_count: 2 }).to_a
|
369
|
+
|
346
370
|
assert_equal(2, responses.length)
|
347
371
|
assert_bulk_index(responses[0]["items"][0])
|
348
372
|
assert_bulk_index(responses[0]["items"][1])
|
@@ -351,12 +375,13 @@ describe Elastomer::Client::Bulk do
|
|
351
375
|
|
352
376
|
it "streams bulk items" do
|
353
377
|
ops = [
|
354
|
-
[:index, { :
|
355
|
-
[:index, { :
|
356
|
-
[:index, { :
|
378
|
+
[:index, { title: "Book 1" }, document_wrapper("book", { _id: 1, _index: @index.name })],
|
379
|
+
[:index, { title: "Book 2" }, document_wrapper("book", { _id: 2, _index: @index.name })],
|
380
|
+
[:index, { title: "Book 3" }, document_wrapper("book", { _id: 3, _index: @index.name })],
|
357
381
|
]
|
358
382
|
items = []
|
359
|
-
$client.bulk_stream_items(ops, { :
|
383
|
+
$client.bulk_stream_items(ops, { action_count: 2 }) { |item| items << item }
|
384
|
+
|
360
385
|
assert_equal(3, items.length)
|
361
386
|
assert_bulk_index(items[0])
|
362
387
|
assert_bulk_index(items[1])
|