elastomer-client 3.2.2 → 6.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/.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 +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 +6 -4
- 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 +165 -143
- 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/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,64 +87,53 @@ 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
|
-
|
|
123
|
+
h = @index.docs("book").get id: book_id
|
|
124
|
+
|
|
125
|
+
refute h["exists"], "was not successfully deleted"
|
|
139
126
|
|
|
140
|
-
h = @index.docs("book").get :
|
|
141
|
-
|
|
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
|
-
items = h["items"]
|
|
150
137
|
|
|
151
138
|
assert_kind_of Integer, h["took"]
|
|
152
139
|
|
|
@@ -155,50 +142,57 @@ describe Elastomer::Client::Bulk do
|
|
|
155
142
|
|
|
156
143
|
@index.refresh
|
|
157
144
|
|
|
158
|
-
h = @index.docs("
|
|
159
|
-
assert_equal "pea53", h["_source"]["author"]
|
|
145
|
+
h = @index.docs("book").get id: 1
|
|
160
146
|
|
|
161
|
-
|
|
162
|
-
assert_equal "John Scalzi", h["_source"]["author"]
|
|
147
|
+
assert_equal "Author 1", h["_source"]["author"]
|
|
163
148
|
|
|
149
|
+
h = @index.docs("book").get id: 2
|
|
150
|
+
|
|
151
|
+
assert_equal "Author 2", h["_source"]["author"]
|
|
164
152
|
|
|
165
153
|
h = @index.bulk do |b|
|
|
166
|
-
b.index '{"author":"
|
|
167
|
-
b.delete :
|
|
154
|
+
b.index '{"author":"Author 3", "title":"Book 3"}', {_id: 3, _type: "book"}
|
|
155
|
+
b.delete ({_id: 1, _type: "book"})
|
|
168
156
|
end
|
|
169
|
-
items = h["items"]
|
|
170
157
|
|
|
171
158
|
assert_bulk_index h["items"].first, "expected to index a book"
|
|
172
159
|
assert_bulk_delete h["items"].last, "expected to delete a book"
|
|
173
160
|
|
|
174
161
|
@index.refresh
|
|
175
162
|
|
|
176
|
-
h = @index.docs("book").get :
|
|
177
|
-
assert !h["exists"], "was not successfully deleted"
|
|
163
|
+
h = @index.docs("book").get id: 1
|
|
178
164
|
|
|
179
|
-
h
|
|
180
|
-
|
|
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"]
|
|
181
170
|
end
|
|
182
171
|
|
|
183
172
|
it "executes a bulk API call when a request size is reached" do
|
|
184
173
|
ary = []
|
|
185
|
-
|
|
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|
|
|
186
178
|
2.times { |num|
|
|
187
|
-
document = {
|
|
188
|
-
ary << b.index(document)
|
|
179
|
+
document = { author: "Author 1", title: book_title}
|
|
180
|
+
ary << b.index(document, { _id: num, _type: "book" })
|
|
189
181
|
}
|
|
190
182
|
ary.compact!
|
|
183
|
+
|
|
191
184
|
assert_equal 0, ary.length
|
|
192
185
|
|
|
193
186
|
7.times { |num|
|
|
194
|
-
document = {
|
|
195
|
-
ary << b.index(document)
|
|
187
|
+
document = { author: "Author 1", title: book_title }
|
|
188
|
+
ary << b.index(document, { _id: num+2, _type: "book" })
|
|
196
189
|
}
|
|
197
190
|
ary.compact!
|
|
191
|
+
|
|
198
192
|
assert_equal 4, ary.length
|
|
199
193
|
|
|
200
|
-
document = {:
|
|
201
|
-
ary << b.index(document)
|
|
194
|
+
document = {author: "Author 1", title: book_title}
|
|
195
|
+
ary << b.index(document, {_id: 10, _type: "book"})
|
|
202
196
|
end
|
|
203
197
|
ary.compact!
|
|
204
198
|
|
|
@@ -206,30 +200,36 @@ describe Elastomer::Client::Bulk do
|
|
|
206
200
|
ary.each { |a| a["items"].each { |b| assert_bulk_index(b) } }
|
|
207
201
|
|
|
208
202
|
@index.refresh
|
|
209
|
-
h = @index.docs.search :
|
|
203
|
+
h = @index.docs.search q: "*:*", size: 0
|
|
210
204
|
|
|
211
|
-
|
|
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
|
|
212
210
|
end
|
|
213
211
|
|
|
214
212
|
it "executes a bulk API call when an action count is reached" do
|
|
215
213
|
ary = []
|
|
216
|
-
ary << @index.bulk(:
|
|
214
|
+
ary << @index.bulk(action_count: 3) do |b|
|
|
217
215
|
2.times { |num|
|
|
218
|
-
document = {:
|
|
219
|
-
ary << b.index(document)
|
|
216
|
+
document = {author: "Author 1", title: "This is book number #{num}"}
|
|
217
|
+
ary << b.index(document, {_id: num, _type: "book"})
|
|
220
218
|
}
|
|
221
219
|
ary.compact!
|
|
220
|
+
|
|
222
221
|
assert_equal 0, ary.length
|
|
223
222
|
|
|
224
223
|
7.times { |num|
|
|
225
|
-
document = {:
|
|
226
|
-
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"})
|
|
227
226
|
}
|
|
228
227
|
ary.compact!
|
|
228
|
+
|
|
229
229
|
assert_equal 2, ary.length
|
|
230
230
|
|
|
231
|
-
document = {:
|
|
232
|
-
ary << b.index(document)
|
|
231
|
+
document = {author: "Author 1", title: "This is book number 10"}
|
|
232
|
+
ary << b.index(document, {_id: 10, _type: "book"})
|
|
233
233
|
end
|
|
234
234
|
ary.compact!
|
|
235
235
|
|
|
@@ -237,26 +237,32 @@ describe Elastomer::Client::Bulk do
|
|
|
237
237
|
ary.each { |a| a["items"].each { |b| assert_bulk_index(b) } }
|
|
238
238
|
|
|
239
239
|
@index.refresh
|
|
240
|
-
h = @index.docs.search :
|
|
240
|
+
h = @index.docs.search q: "*:*", size: 0
|
|
241
241
|
|
|
242
|
-
|
|
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
|
|
243
247
|
end
|
|
244
248
|
|
|
245
|
-
it "rejects documents that
|
|
246
|
-
client =
|
|
249
|
+
it "rejects documents that exceed the maximum request size" do
|
|
250
|
+
client = ElastomerClient::Client.new(**$client_params.merge(max_request_size: 300))
|
|
247
251
|
index = client.index(@name)
|
|
248
252
|
|
|
249
253
|
ary = []
|
|
250
|
-
|
|
254
|
+
book_title = $client.version_support.es_version_8_plus? ? "A"*52 : "A"*34
|
|
255
|
+
ary << index.bulk(request_size: 300) do |b|
|
|
251
256
|
2.times { |num|
|
|
252
|
-
document = {:
|
|
253
|
-
ary << b.index(document)
|
|
257
|
+
document = {author: "Author 1", title: book_title}
|
|
258
|
+
ary << b.index(document, document_wrapper("book", { _id: num }))
|
|
254
259
|
}
|
|
255
260
|
ary.compact!
|
|
261
|
+
|
|
256
262
|
assert_equal 0, ary.length
|
|
257
263
|
|
|
258
|
-
document = {
|
|
259
|
-
assert_raises(
|
|
264
|
+
document = { author: "Author 1", message: "A"*290 }
|
|
265
|
+
assert_raises(ElastomerClient::Client::RequestSizeError) { b.index(document, document_wrapper("book", { _id: 342 })) }
|
|
260
266
|
end
|
|
261
267
|
ary.compact!
|
|
262
268
|
|
|
@@ -264,88 +270,103 @@ describe Elastomer::Client::Bulk do
|
|
|
264
270
|
ary.each { |a| a["items"].each { |b| assert_bulk_index(b) } }
|
|
265
271
|
|
|
266
272
|
index.refresh
|
|
267
|
-
h = index.docs.search :
|
|
273
|
+
h = index.docs.search q: "*:*", size: 0
|
|
268
274
|
|
|
269
|
-
|
|
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
|
|
270
280
|
end
|
|
271
281
|
|
|
272
|
-
it "uses :id from parameters" do
|
|
282
|
+
it "uses :id from parameters and supports symbol and string parameters" do
|
|
273
283
|
response = @index.bulk do |b|
|
|
274
|
-
|
|
275
|
-
|
|
284
|
+
document1 = { author: "Author 1", title: "Book 1" }
|
|
285
|
+
b.index document1, { id: "foo", type: "book" }
|
|
276
286
|
|
|
277
|
-
|
|
287
|
+
document2 = { author: "Author 2", title: "Book 2" }
|
|
288
|
+
b.index document2, { "id" => "bar", "type" => "book" }
|
|
278
289
|
end
|
|
279
290
|
|
|
280
291
|
assert_kind_of Integer, response["took"]
|
|
281
292
|
|
|
282
293
|
items = response["items"]
|
|
294
|
+
|
|
283
295
|
assert_bulk_index(items[0])
|
|
284
296
|
|
|
285
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"]
|
|
286
302
|
end
|
|
287
303
|
|
|
288
|
-
it "
|
|
304
|
+
it "empty symbol and string parameters don't set id" do
|
|
289
305
|
response = @index.bulk do |b|
|
|
290
|
-
|
|
291
|
-
b.index
|
|
306
|
+
document1 = { author: "Author 1", title: "Book 1" }
|
|
307
|
+
b.index document1, { id: "", type: "book" }
|
|
292
308
|
|
|
293
|
-
|
|
294
|
-
b.index
|
|
309
|
+
document2 = { author: "Author 2", title: "Book 2" }
|
|
310
|
+
b.index document2, { "id" => "", "type" => "book" }
|
|
295
311
|
end
|
|
296
312
|
|
|
297
313
|
assert_kind_of Integer, response["took"]
|
|
298
314
|
|
|
299
315
|
items = response["items"]
|
|
316
|
+
|
|
300
317
|
assert_bulk_index(items[0])
|
|
301
|
-
assert_bulk_index(items[1])
|
|
302
318
|
|
|
303
|
-
|
|
304
|
-
|
|
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"]
|
|
305
325
|
end
|
|
306
326
|
|
|
307
|
-
it
|
|
308
|
-
document = { :
|
|
309
|
-
params = { :id => 2 }
|
|
327
|
+
it "supports the routing parameter on index actions" do
|
|
328
|
+
document = { title: "Book 1" }
|
|
310
329
|
|
|
311
330
|
response = @index.bulk do |b|
|
|
312
|
-
b.index document,
|
|
331
|
+
b.index document, { routing: "custom", _id: 1, _type: "book" }
|
|
313
332
|
end
|
|
314
333
|
|
|
315
|
-
assert_kind_of Integer, response["took"]
|
|
316
|
-
|
|
317
334
|
items = response["items"]
|
|
318
|
-
assert_bulk_index(items[0])
|
|
319
335
|
|
|
320
|
-
|
|
321
|
-
|
|
336
|
+
assert_kind_of Integer, response["took"]
|
|
337
|
+
assert_bulk_index(items[0])
|
|
338
|
+
assert_equal "custom", @index.docs("book").get(id: 1)["_routing"]
|
|
322
339
|
end
|
|
323
340
|
|
|
324
|
-
it
|
|
325
|
-
document = { :
|
|
326
|
-
|
|
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
|
|
327
350
|
|
|
328
351
|
response = @index.bulk do |b|
|
|
329
352
|
b.index document, params
|
|
330
353
|
end
|
|
331
354
|
|
|
332
|
-
assert_kind_of Integer, response["took"]
|
|
333
|
-
|
|
334
355
|
items = response["items"]
|
|
335
|
-
assert_bulk_index(items[0])
|
|
336
356
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
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"]
|
|
340
360
|
end
|
|
341
361
|
|
|
342
362
|
it "streams bulk responses" do
|
|
343
363
|
ops = [
|
|
344
|
-
[:index, { :
|
|
345
|
-
[:index, { :
|
|
346
|
-
[: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 })],
|
|
347
367
|
]
|
|
348
|
-
responses = $client.bulk_stream_responses(ops, { :
|
|
368
|
+
responses = $client.bulk_stream_responses(ops, { action_count: 2 }).to_a
|
|
369
|
+
|
|
349
370
|
assert_equal(2, responses.length)
|
|
350
371
|
assert_bulk_index(responses[0]["items"][0])
|
|
351
372
|
assert_bulk_index(responses[0]["items"][1])
|
|
@@ -354,12 +375,13 @@ describe Elastomer::Client::Bulk do
|
|
|
354
375
|
|
|
355
376
|
it "streams bulk items" do
|
|
356
377
|
ops = [
|
|
357
|
-
[:index, { :
|
|
358
|
-
[:index, { :
|
|
359
|
-
[: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 })],
|
|
360
381
|
]
|
|
361
382
|
items = []
|
|
362
|
-
$client.bulk_stream_items(ops, { :
|
|
383
|
+
$client.bulk_stream_items(ops, { action_count: 2 }) { |item| items << item }
|
|
384
|
+
|
|
363
385
|
assert_equal(3, items.length)
|
|
364
386
|
assert_bulk_index(items[0])
|
|
365
387
|
assert_bulk_index(items[1])
|