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
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ElastomerClient
|
2
4
|
class Client
|
3
5
|
|
4
6
|
# Provides access to index-level API commands. An index name is required for
|
@@ -11,7 +13,7 @@ module Elastomer
|
|
11
13
|
# name - The name of the index as a String or an Array of names
|
12
14
|
#
|
13
15
|
# Returns an Index instance.
|
14
|
-
def index(
|
16
|
+
def index(name = nil)
|
15
17
|
Index.new self, name
|
16
18
|
end
|
17
19
|
|
@@ -19,10 +21,10 @@ module Elastomer
|
|
19
21
|
# Create a new index client for making API requests that pertain to
|
20
22
|
# the health and management of individual indexes.
|
21
23
|
#
|
22
|
-
# client -
|
24
|
+
# client - ElastomerClient::Client used for HTTP requests to the server
|
23
25
|
# name - The name of the index as a String or an Array of names
|
24
26
|
#
|
25
|
-
def initialize(
|
27
|
+
def initialize(client, name)
|
26
28
|
@client = client
|
27
29
|
@name = @client.assert_param_presence(name, "index name") unless name.nil?
|
28
30
|
end
|
@@ -39,7 +41,7 @@ module Elastomer
|
|
39
41
|
# and https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-types-exists.html
|
40
42
|
#
|
41
43
|
# Returns true if the index (or type) exists
|
42
|
-
def exists?(
|
44
|
+
def exists?(params = {})
|
43
45
|
response = client.head "/{index}{/type}", update_params(params, action: "index.exists", rest_api: "indices.exists")
|
44
46
|
response.success?
|
45
47
|
end
|
@@ -53,8 +55,8 @@ module Elastomer
|
|
53
55
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html
|
54
56
|
#
|
55
57
|
# Returns the response body as a Hash
|
56
|
-
def create(
|
57
|
-
response = client.put "/{index}", update_params(params, body
|
58
|
+
def create(body, params = {})
|
59
|
+
response = client.put "/{index}", update_params(params, body:, action: "index.create", rest_api: "indices.create")
|
58
60
|
response.body
|
59
61
|
end
|
60
62
|
|
@@ -65,7 +67,7 @@ module Elastomer
|
|
65
67
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-delete-index.html
|
66
68
|
#
|
67
69
|
# Returns the response body as a Hash
|
68
|
-
def delete(
|
70
|
+
def delete(params = {})
|
69
71
|
response = client.delete "/{index}", update_params(params, action: "index.delete", rest_api: "indices.delete")
|
70
72
|
response.body
|
71
73
|
end
|
@@ -77,7 +79,7 @@ module Elastomer
|
|
77
79
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-open-close.html
|
78
80
|
#
|
79
81
|
# Returns the response body as a Hash
|
80
|
-
def open(
|
82
|
+
def open(params = {})
|
81
83
|
response = client.post "/{index}/_open", update_params(params, action: "index.open", rest_api: "indices.open")
|
82
84
|
response.body
|
83
85
|
end
|
@@ -89,7 +91,7 @@ module Elastomer
|
|
89
91
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-open-close.html
|
90
92
|
#
|
91
93
|
# Returns the response body as a Hash
|
92
|
-
def close(
|
94
|
+
def close(params = {})
|
93
95
|
response = client.post "/{index}/_close", update_params(params, action: "index.close", rest_api: "indices.close")
|
94
96
|
response.body
|
95
97
|
end
|
@@ -101,7 +103,7 @@ module Elastomer
|
|
101
103
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-settings.html
|
102
104
|
#
|
103
105
|
# Returns the response body as a Hash
|
104
|
-
def get_settings(
|
106
|
+
def get_settings(params = {})
|
105
107
|
response = client.get "{/index}/_settings", update_params(params, action: "index.get_settings", rest_api: "indices.get_settings")
|
106
108
|
response.body
|
107
109
|
end
|
@@ -115,8 +117,8 @@ module Elastomer
|
|
115
117
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-update-settings.html
|
116
118
|
#
|
117
119
|
# Returns the response body as a Hash
|
118
|
-
def update_settings(
|
119
|
-
response = client.put "{/index}/_settings", update_params(params, body
|
120
|
+
def update_settings(body, params = {})
|
121
|
+
response = client.put "{/index}/_settings", update_params(params, body:, action: "index.update_settings", rest_api: "indices.put_settings")
|
120
122
|
response.body
|
121
123
|
end
|
122
124
|
|
@@ -129,7 +131,7 @@ module Elastomer
|
|
129
131
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html
|
130
132
|
#
|
131
133
|
# Returns the response body as a Hash
|
132
|
-
def get_mapping(
|
134
|
+
def get_mapping(params = {})
|
133
135
|
response = client.get "/{index}/_mapping{/type}", update_params(params, action: "index.get_mapping", rest_api: "indices.get_mapping")
|
134
136
|
response.body
|
135
137
|
end
|
@@ -144,8 +146,8 @@ module Elastomer
|
|
144
146
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html
|
145
147
|
#
|
146
148
|
# Returns the response body as a Hash
|
147
|
-
def update_mapping(
|
148
|
-
response = client.put "/{index}/_mapping/
|
149
|
+
def update_mapping(type, body, params = {})
|
150
|
+
response = client.put "/{index}/_mapping{/type}", update_params(params, body:, type:, action: "index.update_mapping", rest_api: "indices.put_mapping")
|
149
151
|
response.body
|
150
152
|
end
|
151
153
|
alias_method :put_mapping, :update_mapping
|
@@ -157,7 +159,7 @@ module Elastomer
|
|
157
159
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html
|
158
160
|
#
|
159
161
|
# Returns the response body as a Hash
|
160
|
-
def get_aliases(
|
162
|
+
def get_aliases(params = {})
|
161
163
|
response = client.get "/{index}/_alias", update_params(action: "index.get_aliases", rest_api: "indices.get_alias")
|
162
164
|
response.body
|
163
165
|
end
|
@@ -178,8 +180,8 @@ module Elastomer
|
|
178
180
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html
|
179
181
|
#
|
180
182
|
# Returns the response body as a Hash
|
181
|
-
def get_alias(
|
182
|
-
response = client.get "/{index}/_alias/{name}", update_params(params, name
|
183
|
+
def get_alias(name, params = {})
|
184
|
+
response = client.get "/{index}/_alias/{name}", update_params(params, name:, action: "index.get_alias", rest_api: "indices.get_alias")
|
183
185
|
response.body
|
184
186
|
end
|
185
187
|
|
@@ -197,8 +199,8 @@ module Elastomer
|
|
197
199
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html
|
198
200
|
#
|
199
201
|
# Returns the response body as a Hash
|
200
|
-
def add_alias(
|
201
|
-
response = client.put "/{index}/_alias/{name}", update_params(params, name
|
202
|
+
def add_alias(name, params = {})
|
203
|
+
response = client.put "/{index}/_alias/{name}", update_params(params, name:, action: "index.add_alias", rest_api: "indices.put_alias")
|
202
204
|
response.body
|
203
205
|
end
|
204
206
|
|
@@ -215,8 +217,8 @@ module Elastomer
|
|
215
217
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html
|
216
218
|
#
|
217
219
|
# Returns the response body as a Hash
|
218
|
-
def delete_alias(
|
219
|
-
response = client.delete "/{index}/_alias/{name}", update_params(params, name
|
220
|
+
def delete_alias(name, params = {})
|
221
|
+
response = client.delete "/{index}/_alias/{name}", update_params(params, name:, action: "index.delete_alias", rest_api: "indices.delete_alias")
|
220
222
|
response.body
|
221
223
|
end
|
222
224
|
|
@@ -229,9 +231,9 @@ module Elastomer
|
|
229
231
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-analyze.html
|
230
232
|
#
|
231
233
|
# Returns the response body as a Hash
|
232
|
-
def analyze(
|
234
|
+
def analyze(text, params = {})
|
233
235
|
body = text.is_a?(Hash) ? text : {text: text.to_s}
|
234
|
-
response = client.get "{/index}/_analyze", update_params(params, body
|
236
|
+
response = client.get "{/index}/_analyze", update_params(params, body:, action: "index.analyze", rest_api: "indices.analyze")
|
235
237
|
response.body
|
236
238
|
end
|
237
239
|
|
@@ -244,7 +246,7 @@ module Elastomer
|
|
244
246
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-refresh.html
|
245
247
|
#
|
246
248
|
# Returns the response body as a Hash
|
247
|
-
def refresh(
|
249
|
+
def refresh(params = {})
|
248
250
|
response = client.post "{/index}/_refresh", update_params(params, action: "index.refresh", rest_api: "indices.refresh")
|
249
251
|
response.body
|
250
252
|
end
|
@@ -257,7 +259,7 @@ module Elastomer
|
|
257
259
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-flush.html
|
258
260
|
#
|
259
261
|
# Returns the response body as a Hash
|
260
|
-
def flush(
|
262
|
+
def flush(params = {})
|
261
263
|
response = client.post "{/index}/_flush", update_params(params, action: "index.flush", rest_api: "indices.flush")
|
262
264
|
response.body
|
263
265
|
end
|
@@ -271,7 +273,7 @@ module Elastomer
|
|
271
273
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-forcemerge.html
|
272
274
|
#
|
273
275
|
# Returns the response body as a Hash
|
274
|
-
def forcemerge(
|
276
|
+
def forcemerge(params = {})
|
275
277
|
response = client.post "{/index}/_forcemerge", update_params(params, action: "index.forcemerge", rest_api: "indices.forcemerge")
|
276
278
|
response.body
|
277
279
|
end
|
@@ -286,7 +288,7 @@ module Elastomer
|
|
286
288
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-recovery.html
|
287
289
|
#
|
288
290
|
# Returns the response body as a Hash
|
289
|
-
def recovery(
|
291
|
+
def recovery(params = {})
|
290
292
|
response = client.get "{/index}/_recovery", update_params(params, action: "index.recovery", rest_api: "indices.recovery")
|
291
293
|
response.body
|
292
294
|
end
|
@@ -300,7 +302,7 @@ module Elastomer
|
|
300
302
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-clearcache.html
|
301
303
|
#
|
302
304
|
# Returns the response body as a Hash
|
303
|
-
def clear_cache(
|
305
|
+
def clear_cache(params = {})
|
304
306
|
response = client.post "{/index}/_cache/clear", update_params(params, action: "index.clear_cache", rest_api: "indices.clear_cache")
|
305
307
|
response.body
|
306
308
|
end
|
@@ -319,7 +321,7 @@ module Elastomer
|
|
319
321
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-stats.html
|
320
322
|
#
|
321
323
|
# Returns the response body as a Hash
|
322
|
-
def stats(
|
324
|
+
def stats(params = {})
|
323
325
|
response = client.get "{/index}/_stats{/stats}", update_params(params, action: "index.stats", rest_api: "indices.stats")
|
324
326
|
response.body
|
325
327
|
end
|
@@ -332,7 +334,7 @@ module Elastomer
|
|
332
334
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-segments.html
|
333
335
|
#
|
334
336
|
# Returns the response body as a Hash
|
335
|
-
def segments(
|
337
|
+
def segments(params = {})
|
336
338
|
response = client.get "{/index}/_segments", update_params(params, action: "index.segments", rest_api: "indices.segments")
|
337
339
|
response.body
|
338
340
|
end
|
@@ -345,7 +347,8 @@ module Elastomer
|
|
345
347
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/docs.html
|
346
348
|
#
|
347
349
|
# Returns a Docs instance.
|
348
|
-
def docs(
|
350
|
+
def docs(type = nil)
|
351
|
+
type = "_doc" if client.version_support.es_version_8_plus?
|
349
352
|
client.docs name, type
|
350
353
|
end
|
351
354
|
|
@@ -384,7 +387,7 @@ module Elastomer
|
|
384
387
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html
|
385
388
|
#
|
386
389
|
# Returns the response body as a Hash
|
387
|
-
def bulk(
|
390
|
+
def bulk(params = {}, &block)
|
388
391
|
raise "a block is required" if block.nil?
|
389
392
|
|
390
393
|
params = {index: self.name}.merge params
|
@@ -412,7 +415,7 @@ module Elastomer
|
|
412
415
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html
|
413
416
|
#
|
414
417
|
# Returns a new Scroller instance
|
415
|
-
def scroll(
|
418
|
+
def scroll(query, opts = {})
|
416
419
|
opts = {index: name}.merge opts
|
417
420
|
client.scroll query, opts
|
418
421
|
end
|
@@ -441,7 +444,7 @@ module Elastomer
|
|
441
444
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html
|
442
445
|
#
|
443
446
|
# Returns a new Scroller instance
|
444
|
-
def scan(
|
447
|
+
def scan(query, opts = {})
|
445
448
|
opts = {index: name}.merge opts
|
446
449
|
client.scan query, opts
|
447
450
|
end
|
@@ -472,7 +475,7 @@ module Elastomer
|
|
472
475
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html
|
473
476
|
#
|
474
477
|
# Returns the response body as a Hash
|
475
|
-
def multi_search(
|
478
|
+
def multi_search(params = {}, &block)
|
476
479
|
raise "a block is required" if block.nil?
|
477
480
|
|
478
481
|
params = {index: self.name}.merge params
|
@@ -504,47 +507,9 @@ module Elastomer
|
|
504
507
|
client.multi_percolate(params, &block)
|
505
508
|
end
|
506
509
|
|
507
|
-
#
|
508
|
-
# requests to warm up the index before it is available for
|
509
|
-
# searching. Warmers are useful for searches that require heavy
|
510
|
-
# data loading, such as faceting or sorting.
|
511
|
-
#
|
512
|
-
# The warmer api allows creating, deleting, and retrieving
|
513
|
-
# registered warmers.
|
514
|
-
#
|
515
|
-
# warmer_name - The name of the warmer to operate on.
|
516
|
-
#
|
517
|
-
# Examples
|
518
|
-
# index.warmer('warmer1').create(query: {match_all: {}})
|
519
|
-
# index.warmer('warmer1').get
|
520
|
-
# index.warmer('warmer1').delete
|
521
|
-
#
|
522
|
-
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-warmers.html
|
523
|
-
#
|
524
|
-
# Returns a new Warmer instance
|
525
|
-
def warmer(warmer_name)
|
526
|
-
Warmer.new(client, name, warmer_name)
|
527
|
-
end
|
528
|
-
|
529
|
-
# Delete documents by query following either the native or
|
530
|
-
# application-level delete by query method.
|
531
|
-
#
|
532
|
-
# NOTE: The parameters and response format varies by version. To have more
|
533
|
-
# control over this, use app_delete_by_query or native_delete_by_query
|
534
|
-
# directly.
|
510
|
+
# Delete documents by query
|
535
511
|
def delete_by_query(query, params = nil)
|
536
|
-
docs.send(
|
537
|
-
end
|
538
|
-
|
539
|
-
# DEPRECATED: Delete documents from one or more indices and one or more types based
|
540
|
-
# on a query using application-level logic.
|
541
|
-
#
|
542
|
-
# See Client#app_delete_by_query for more information.
|
543
|
-
#
|
544
|
-
# Returns a Hash of statistics about the delete operations simulating the
|
545
|
-
# Elasticsearch 2.x delete by query plugin's output.
|
546
|
-
def app_delete_by_query(query, params = nil)
|
547
|
-
docs.app_delete_by_query(query, params)
|
512
|
+
docs.send(:native_delete_by_query, query, params)
|
548
513
|
end
|
549
514
|
|
550
515
|
# Delete documents from one or more indices and one or more types based
|
@@ -555,12 +520,22 @@ module Elastomer
|
|
555
520
|
# Returns a Hash of statistics about the delete operations as returned by
|
556
521
|
# _delete_by_query.
|
557
522
|
#
|
558
|
-
# Raises
|
523
|
+
# Raises ElastomerClient::Client::IncompatibleVersionException if this version
|
559
524
|
# of Elasticsearch does not support _delete_by_query.
|
560
525
|
def native_delete_by_query(query, params = nil)
|
561
526
|
docs.native_delete_by_query(query, params)
|
562
527
|
end
|
563
528
|
|
529
|
+
# Update documents by query using Elasticsearch's _update_by_query API.
|
530
|
+
#
|
531
|
+
# See Client#update_by_query for more information.
|
532
|
+
#
|
533
|
+
# Returns a Hash of statistics about the update operations as returned by
|
534
|
+
# _update_by_query.
|
535
|
+
def update_by_query(query, params = nil)
|
536
|
+
docs.update_by_query(query, params)
|
537
|
+
end
|
538
|
+
|
564
539
|
# Constructs a Percolator with the given id on this index.
|
565
540
|
#
|
566
541
|
# Examples
|
@@ -579,9 +554,10 @@ module Elastomer
|
|
579
554
|
# overrides - Optional parameter overrides as a Hash
|
580
555
|
#
|
581
556
|
# Returns a new params Hash.
|
582
|
-
def update_params(
|
557
|
+
def update_params(params, overrides = nil)
|
583
558
|
h = defaults.update params
|
584
559
|
h.update overrides unless overrides.nil?
|
560
|
+
h.delete(:type) if client.version_support.es_version_8_plus?
|
585
561
|
h
|
586
562
|
end
|
587
563
|
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ElastomerClient
|
2
4
|
class Client
|
3
5
|
|
4
6
|
# Execute an array of percolate actions in bulk. Results are returned in an
|
@@ -40,7 +42,7 @@ module Elastomer
|
|
40
42
|
raise "multi_percolate request body cannot be nil" if body.nil?
|
41
43
|
params ||= {}
|
42
44
|
|
43
|
-
response = self.post "{/index}{/type}/_mpercolate", params.merge(body
|
45
|
+
response = self.post "{/index}{/type}/_mpercolate", params.merge(body:, action: "mpercolate", rest_api: "mpercolate")
|
44
46
|
response.body
|
45
47
|
end
|
46
48
|
end
|
@@ -61,7 +63,7 @@ module Elastomer
|
|
61
63
|
# Create a new MultiPercolate instance for accumulating percolate actions
|
62
64
|
# and submitting them all as a single request.
|
63
65
|
#
|
64
|
-
# client -
|
66
|
+
# client - ElastomerClient::Client used for HTTP requests to the server
|
65
67
|
# params - Parameters Hash to pass to the Client#multi_percolate method
|
66
68
|
def initialize(client, params = {})
|
67
69
|
@client = client
|
@@ -81,7 +83,7 @@ module Elastomer
|
|
81
83
|
# Returns this MultiPercolate instance.
|
82
84
|
def percolate(doc, header = {})
|
83
85
|
add_to_actions(percolate: @params.merge(header))
|
84
|
-
add_to_actions(doc:
|
86
|
+
add_to_actions(doc:)
|
85
87
|
end
|
86
88
|
|
87
89
|
# Add a percolate acount action to the multi percolate request. This
|
@@ -94,7 +96,7 @@ module Elastomer
|
|
94
96
|
# Returns this MultiPercolate instance.
|
95
97
|
def count(doc, header = {})
|
96
98
|
add_to_actions(count: @params.merge(header))
|
97
|
-
add_to_actions(doc:
|
99
|
+
add_to_actions(doc:)
|
98
100
|
end
|
99
101
|
|
100
102
|
# Execute the multi_percolate call with the accumulated percolate actions.
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ElastomerClient
|
2
4
|
class Client
|
3
5
|
|
4
6
|
# Execute an array of searches in bulk. Results are returned in an
|
@@ -40,7 +42,7 @@ module Elastomer
|
|
40
42
|
raise "multi_search request body cannot be nil" if body.nil?
|
41
43
|
params ||= {}
|
42
44
|
|
43
|
-
response = self.post "{/index}{/type}/_msearch", params.merge(body
|
45
|
+
response = self.post "{/index}{/type}/_msearch", params.merge(body:, action: "msearch", rest_api: "msearch")
|
44
46
|
response.body
|
45
47
|
end
|
46
48
|
end
|
@@ -61,7 +63,7 @@ module Elastomer
|
|
61
63
|
# Create a new MultiSearch instance for accumulating searches and
|
62
64
|
# submitting them all as a single request.
|
63
65
|
#
|
64
|
-
# client -
|
66
|
+
# client - ElastomerClient::Client used for HTTP requests to the server
|
65
67
|
# params - Parameters Hash to pass to the Client#multi_search method
|
66
68
|
def initialize(client, params = {})
|
67
69
|
@client = client
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ElastomerClient
|
2
4
|
class Client
|
3
5
|
# Delete documents based on a query using the Elasticsearch _delete_by_query API.
|
4
6
|
#
|
@@ -21,10 +23,6 @@ module Elastomer
|
|
21
23
|
attr_reader :client, :query, :parameters
|
22
24
|
|
23
25
|
def initialize(client, query, parameters)
|
24
|
-
unless client.version_support.native_delete_by_query?
|
25
|
-
raise IncompatibleVersionException, "Elasticsearch '#{client.version}' does not support _delete_by_query"
|
26
|
-
end
|
27
|
-
|
28
26
|
@client = client
|
29
27
|
@query = query
|
30
28
|
@parameters = parameters
|
@@ -32,7 +30,9 @@ module Elastomer
|
|
32
30
|
|
33
31
|
def execute
|
34
32
|
# TODO: Require index parameter. type is optional.
|
35
|
-
|
33
|
+
updated_params = parameters.merge(body: query, action: "delete_by_query", rest_api: "delete_by_query")
|
34
|
+
updated_params.delete(:type) if client.version_support.es_version_8_plus?
|
35
|
+
response = client.post("/{index}{/type}/_delete_by_query", updated_params)
|
36
36
|
response.body
|
37
37
|
end
|
38
38
|
end
|
@@ -1,5 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
|
-
module
|
3
|
+
module ElastomerClient
|
3
4
|
class Client
|
4
5
|
|
5
6
|
# Provides access to node-level API commands. The default node is set to
|
@@ -10,7 +11,7 @@ module Elastomer
|
|
10
11
|
# node_id - The node ID as a String or an Array of node IDs
|
11
12
|
#
|
12
13
|
# Returns a Nodes instance.
|
13
|
-
def nodes(
|
14
|
+
def nodes(node_id = nil)
|
14
15
|
Nodes.new self, node_id
|
15
16
|
end
|
16
17
|
|
@@ -19,10 +20,10 @@ module Elastomer
|
|
19
20
|
# Create a new nodes client for making API requests that pertain to
|
20
21
|
# the health and management individual nodes.
|
21
22
|
#
|
22
|
-
# client -
|
23
|
+
# client - ElastomerClient::Client used for HTTP requests to the server
|
23
24
|
# node_id - The node ID as a String or an Array of node IDs
|
24
25
|
#
|
25
|
-
def initialize(
|
26
|
+
def initialize(client, node_id)
|
26
27
|
@client = client
|
27
28
|
@node_id = node_id
|
28
29
|
end
|
@@ -30,7 +31,7 @@ module Elastomer
|
|
30
31
|
attr_reader :client, :node_id
|
31
32
|
|
32
33
|
# Retrieve one or more (or all) of the cluster nodes information. By
|
33
|
-
# default all information is returned from all
|
34
|
+
# default all information is returned from all nodes. You can select the
|
34
35
|
# information to be returned by passing in the `:info` from the list of
|
35
36
|
# "settings", "os", "process", "jvm", "thread_pool", "network",
|
36
37
|
# "transport", "http" and "plugins".
|
@@ -48,7 +49,7 @@ module Elastomer
|
|
48
49
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-nodes-info.html
|
49
50
|
#
|
50
51
|
# Returns the response as a Hash
|
51
|
-
def info(
|
52
|
+
def info(params = {})
|
52
53
|
response = client.get "/_nodes{/node_id}{/info}", update_params(params, action: "nodes.info", rest_api: "nodes.info")
|
53
54
|
response.body
|
54
55
|
end
|
@@ -68,7 +69,7 @@ module Elastomer
|
|
68
69
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-nodes-stats.html
|
69
70
|
#
|
70
71
|
# Returns the response as a Hash
|
71
|
-
def stats(
|
72
|
+
def stats(params = {})
|
72
73
|
response = client.get "/_nodes{/node_id}/stats{/stats}", update_params(params, action: "nodes.stats", rest_api: "nodes.stats")
|
73
74
|
response.body
|
74
75
|
end
|
@@ -86,7 +87,7 @@ module Elastomer
|
|
86
87
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-nodes-hot-threads.html
|
87
88
|
#
|
88
89
|
# Returns the response as a String
|
89
|
-
def hot_threads(
|
90
|
+
def hot_threads(params = {})
|
90
91
|
response = client.get "/_nodes{/node_id}/hot_threads", update_params(params, action: "nodes.hot_threads", rest_api: "nodes.hot_threads")
|
91
92
|
response.body
|
92
93
|
end
|
@@ -98,8 +99,8 @@ module Elastomer
|
|
98
99
|
# overrides - Optional parameter overrides as a Hash
|
99
100
|
#
|
100
101
|
# Returns a new params Hash.
|
101
|
-
def update_params(
|
102
|
-
h = { :
|
102
|
+
def update_params(params, overrides = nil)
|
103
|
+
h = { node_id: }.update params
|
103
104
|
h.update overrides unless overrides.nil?
|
104
105
|
h
|
105
106
|
end
|
@@ -1,20 +1,19 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ElastomerClient
|
2
4
|
class Client
|
3
5
|
|
4
6
|
class Percolator
|
5
7
|
|
6
8
|
# Create a new Percolator for managing a query.
|
7
9
|
#
|
8
|
-
# client -
|
10
|
+
# client - ElastomerClient::Client used for HTTP requests to the server
|
9
11
|
# index_name - The index name
|
10
12
|
# id - The _id for the query
|
11
13
|
def initialize(client, index_name, id)
|
12
14
|
@client = client
|
13
15
|
@index_name = client.assert_param_presence(index_name, "index name")
|
14
16
|
@id = client.assert_param_presence(id, "id")
|
15
|
-
|
16
|
-
# COMPATIBILITY
|
17
|
-
@percolator_type = client.version_support.percolator_type
|
18
17
|
end
|
19
18
|
|
20
19
|
attr_reader :client, :index_name, :id
|
@@ -28,7 +27,7 @@ module Elastomer
|
|
28
27
|
#
|
29
28
|
# Returns the response body as a Hash
|
30
29
|
def create(body, params = {})
|
31
|
-
response = client.put("/{index}
|
30
|
+
response = client.put("/{index}/percolator/{id}", defaults.merge(params.merge(body:, action: "percolator.create")))
|
32
31
|
response.body
|
33
32
|
end
|
34
33
|
|
@@ -41,7 +40,7 @@ module Elastomer
|
|
41
40
|
#
|
42
41
|
# Returns the response body as a Hash
|
43
42
|
def get(params = {})
|
44
|
-
response = client.get("/{index}
|
43
|
+
response = client.get("/{index}/percolator/{id}", defaults.merge(params.merge(action: "percolator.get")))
|
45
44
|
response.body
|
46
45
|
end
|
47
46
|
|
@@ -54,7 +53,7 @@ module Elastomer
|
|
54
53
|
#
|
55
54
|
# Returns the response body as a Hash
|
56
55
|
def delete(params = {})
|
57
|
-
response = client.delete("/{index}
|
56
|
+
response = client.delete("/{index}/percolator/{id}", defaults.merge(params.merge(action: "percolator.delete")))
|
58
57
|
response.body
|
59
58
|
end
|
60
59
|
|
@@ -72,9 +71,9 @@ module Elastomer
|
|
72
71
|
|
73
72
|
# Internal: Returns a Hash containing default parameters.
|
74
73
|
def defaults
|
75
|
-
{index: index_name, id:
|
74
|
+
{index: index_name, id:}
|
76
75
|
end
|
77
76
|
|
78
77
|
end # Percolator
|
79
78
|
end # Client
|
80
|
-
end #
|
79
|
+
end # ElastomerClient
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ElastomerClient
|
4
|
+
class Client
|
5
|
+
|
6
|
+
# Returns a Reindex instance
|
7
|
+
def reindex
|
8
|
+
Reindex.new(self)
|
9
|
+
end
|
10
|
+
|
11
|
+
class Reindex
|
12
|
+
# Create a new Reindex for initiating reindex tasks.
|
13
|
+
# More context: https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html
|
14
|
+
#
|
15
|
+
# client - ElastomerClient::Client used for HTTP requests to the server
|
16
|
+
def initialize(client)
|
17
|
+
@client = client
|
18
|
+
end
|
19
|
+
|
20
|
+
attr_reader :client
|
21
|
+
|
22
|
+
def reindex(body, params = {})
|
23
|
+
response = client.post "/_reindex", params.merge(params, body:, action: "reindex", rest_api: "reindex")
|
24
|
+
response.body
|
25
|
+
end
|
26
|
+
|
27
|
+
def rethrottle(task_id, params = {})
|
28
|
+
response = client.post "/_reindex/#{task_id}/_rethrottle", params.merge(params, action: "rethrottle", rest_api: "reindex")
|
29
|
+
response.body
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ElastomerClient
|
2
4
|
class Client
|
3
5
|
|
4
6
|
# Returns a Repository instance.
|
@@ -10,7 +12,7 @@ module Elastomer
|
|
10
12
|
# Create a new index client for making API requests that pertain to
|
11
13
|
# the health and management individual indexes.
|
12
14
|
#
|
13
|
-
# client -
|
15
|
+
# client - ElastomerClient::Client used for HTTP requests to the server
|
14
16
|
# name - The name of the index as a String or an Array of names
|
15
17
|
def initialize(client, name = nil)
|
16
18
|
@client = client
|
@@ -28,7 +30,7 @@ module Elastomer
|
|
28
30
|
def exists?(params = {})
|
29
31
|
response = client.get "/_snapshot{/repository}", update_params(params, action: "repository.exists", rest_api: "snapshot.get_repository")
|
30
32
|
response.success?
|
31
|
-
rescue
|
33
|
+
rescue ElastomerClient::Client::Error => err
|
32
34
|
if err.error && err.error.dig("root_cause", 0, "type") == "repository_missing_exception"
|
33
35
|
false
|
34
36
|
else
|
@@ -45,7 +47,7 @@ module Elastomer
|
|
45
47
|
#
|
46
48
|
# Returns the response body as a Hash
|
47
49
|
def create(body, params = {})
|
48
|
-
response = client.put "/_snapshot/{repository}", update_params(params, body
|
50
|
+
response = client.put "/_snapshot/{repository}", update_params(params, body:, action: "repository.create", rest_api: "snapshot.create_repository")
|
49
51
|
response.body
|
50
52
|
end
|
51
53
|
|
@@ -79,7 +81,7 @@ module Elastomer
|
|
79
81
|
#
|
80
82
|
# Returns the response body as a Hash
|
81
83
|
def update(body, params = {})
|
82
|
-
response = client.put "/_snapshot/{repository}", update_params(params, body
|
84
|
+
response = client.put "/_snapshot/{repository}", update_params(params, body:, action: "repository.update", rest_api: "snapshot.create_repository")
|
83
85
|
response.body
|
84
86
|
end
|
85
87
|
|