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
|
# Returns a Cluster instance.
|
@@ -11,9 +13,9 @@ module Elastomer
|
|
11
13
|
# Create a new cluster client for making API requests that pertain to
|
12
14
|
# the cluster health and management.
|
13
15
|
#
|
14
|
-
# client -
|
16
|
+
# client - ElastomerClient::Client used for HTTP requests to the server
|
15
17
|
#
|
16
|
-
def initialize(
|
18
|
+
def initialize(client)
|
17
19
|
@client = client
|
18
20
|
end
|
19
21
|
|
@@ -33,7 +35,7 @@ module Elastomer
|
|
33
35
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-health.html
|
34
36
|
#
|
35
37
|
# Returns the response as a Hash
|
36
|
-
def health(
|
38
|
+
def health(params = {})
|
37
39
|
response = client.get "/_cluster/health{/index}", params.merge(action: "cluster.health", rest_api: "cluster.health")
|
38
40
|
response.body
|
39
41
|
end
|
@@ -51,7 +53,7 @@ module Elastomer
|
|
51
53
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-state.html
|
52
54
|
#
|
53
55
|
# Returns the response as a Hash
|
54
|
-
def state(
|
56
|
+
def state(params = {})
|
55
57
|
response = client.get "/_cluster/state{/metrics}{/indices}", params.merge(action: "cluster.state", rest_api: "cluster.state")
|
56
58
|
response.body
|
57
59
|
end
|
@@ -66,7 +68,7 @@ module Elastomer
|
|
66
68
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-stats.html
|
67
69
|
#
|
68
70
|
# Returns the response as a Hash
|
69
|
-
def stats(
|
71
|
+
def stats(params = {})
|
70
72
|
response = client.get "/_cluster/stats", params.merge(action: "cluster.stats", rest_api: "cluster.stats")
|
71
73
|
response.body
|
72
74
|
end
|
@@ -79,7 +81,7 @@ module Elastomer
|
|
79
81
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-pending.html
|
80
82
|
#
|
81
83
|
# Returns the response as a Hash
|
82
|
-
def pending_tasks(
|
84
|
+
def pending_tasks(params = {})
|
83
85
|
response = client.get "/_cluster/pending_tasks", params.merge(action: "cluster.pending_tasks", rest_api: "cluster.pending_tasks")
|
84
86
|
response.body
|
85
87
|
end
|
@@ -89,7 +91,7 @@ module Elastomer
|
|
89
91
|
# does not contain the "tasks" field.
|
90
92
|
def pending_tasks?
|
91
93
|
hash = pending_tasks
|
92
|
-
return nil unless hash.key? "tasks"
|
94
|
+
return nil unless hash.key? "tasks" # rubocop:disable Style/ReturnNilInPredicateMethodDefinition
|
93
95
|
hash["tasks"].length > 0
|
94
96
|
end
|
95
97
|
|
@@ -100,7 +102,7 @@ module Elastomer
|
|
100
102
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-update-settings.html
|
101
103
|
#
|
102
104
|
# Returns the response as a Hash
|
103
|
-
def get_settings(
|
105
|
+
def get_settings(params = {})
|
104
106
|
response = client.get "/_cluster/settings", params.merge(action: "cluster.get_settings", rest_api: "cluster.get_settings")
|
105
107
|
response.body
|
106
108
|
end
|
@@ -116,8 +118,8 @@ module Elastomer
|
|
116
118
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-update-settings.html
|
117
119
|
#
|
118
120
|
# Returns the response as a Hash
|
119
|
-
def update_settings(
|
120
|
-
response = client.put "/_cluster/settings", params.merge(body
|
121
|
+
def update_settings(body, params = {})
|
122
|
+
response = client.put "/_cluster/settings", params.merge(body:, action: "cluster.update_settings", rest_api: "cluster.put_settings")
|
121
123
|
response.body
|
122
124
|
end
|
123
125
|
|
@@ -146,7 +148,7 @@ module Elastomer
|
|
146
148
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-reroute.html
|
147
149
|
#
|
148
150
|
# Returns the response as a Hash
|
149
|
-
def reroute(
|
151
|
+
def reroute(commands, params = {})
|
150
152
|
if commands.is_a?(Hash) && commands.key?(:commands)
|
151
153
|
body = commands
|
152
154
|
elsif commands.is_a?(Hash)
|
@@ -157,7 +159,7 @@ module Elastomer
|
|
157
159
|
body = {commands: Array(commands)}
|
158
160
|
end
|
159
161
|
|
160
|
-
response = client.post "/_cluster/reroute", params.merge(body
|
162
|
+
response = client.post "/_cluster/reroute", params.merge(body:, action: "cluster.reroute", rest_api: "cluster.reroute")
|
161
163
|
response.body
|
162
164
|
end
|
163
165
|
|
@@ -178,7 +180,7 @@ 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_aliases(
|
183
|
+
def get_aliases(params = {})
|
182
184
|
response = client.get "{/index}/_alias{/name}", params.merge(action: "cluster.get_aliases", rest_api: "indices.get_alias")
|
183
185
|
response.body
|
184
186
|
end
|
@@ -204,7 +206,7 @@ module Elastomer
|
|
204
206
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html
|
205
207
|
#
|
206
208
|
# Returns the response body as a Hash
|
207
|
-
def update_aliases(
|
209
|
+
def update_aliases(actions, params = {})
|
208
210
|
if actions.is_a?(Hash) && actions.key?(:actions)
|
209
211
|
body = actions
|
210
212
|
elsif actions.is_a?(Hash)
|
@@ -215,7 +217,7 @@ module Elastomer
|
|
215
217
|
body = {actions: Array(actions)}
|
216
218
|
end
|
217
219
|
|
218
|
-
response = client.post "/_aliases", params.merge(body
|
220
|
+
response = client.post "/_aliases", params.merge(body:, action: "cluster.update_aliases", rest_api: "indices.update_aliases")
|
219
221
|
response.body
|
220
222
|
end
|
221
223
|
|
@@ -1,13 +1,15 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ElastomerClient
|
2
4
|
class Client
|
3
5
|
# Execute delete_by_query using the native _delete_by_query API if supported
|
4
6
|
# or the application-level implementation.
|
5
7
|
#
|
6
8
|
# Warning: These implementations have different parameters and return types.
|
7
|
-
# If you want to use one or the other consistently, use
|
8
|
-
# or
|
9
|
+
# If you want to use one or the other consistently, use ElastomerClient::Client#native_delete_by_query
|
10
|
+
# or ElastomerClient::Client#app_delete_by_query directly.
|
9
11
|
def delete_by_query(query, params = {})
|
10
|
-
send(
|
12
|
+
send(:native_delete_by_query, query, params)
|
11
13
|
end
|
12
14
|
end
|
13
15
|
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 document-level API commands. Indexing documents and
|
@@ -11,7 +12,7 @@ module Elastomer
|
|
11
12
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/docs.html
|
12
13
|
#
|
13
14
|
# Returns a Docs instance.
|
14
|
-
def docs(
|
15
|
+
def docs(name = nil, type = nil)
|
15
16
|
Docs.new self, name, type
|
16
17
|
end
|
17
18
|
|
@@ -19,11 +20,11 @@ module Elastomer
|
|
19
20
|
# Create a new document client for making API requests that pertain to
|
20
21
|
# the indexing and searching of documents in a search index.
|
21
22
|
#
|
22
|
-
# client -
|
23
|
+
# client - ElastomerClient::Client used for HTTP requests to the server
|
23
24
|
# name - The name of the index as a String
|
24
25
|
# type - The document type as a String
|
25
26
|
#
|
26
|
-
def initialize(
|
27
|
+
def initialize(client, name, type = nil)
|
27
28
|
@client = client
|
28
29
|
@name = @client.assert_param_presence(name, "index name") unless name.nil?
|
29
30
|
@type = @client.assert_param_presence(type, "document type") unless type.nil?
|
@@ -54,8 +55,6 @@ module Elastomer
|
|
54
55
|
#
|
55
56
|
# Elasticsearch 2.X only:
|
56
57
|
#
|
57
|
-
# :_timestamp (deprecated)
|
58
|
-
# :_ttl (deprecated)
|
59
58
|
# :_consistency
|
60
59
|
#
|
61
60
|
# Elasticsearch 5.x only:
|
@@ -73,9 +72,9 @@ module Elastomer
|
|
73
72
|
#
|
74
73
|
# Returns the response body as a Hash
|
75
74
|
#
|
76
|
-
# Raises
|
75
|
+
# Raises ElastomerClient::Client::IllegalArgument if an unsupported indexing
|
77
76
|
# directive is used.
|
78
|
-
def index(
|
77
|
+
def index(document, params = {})
|
79
78
|
overrides = from_document document
|
80
79
|
params = update_params(params, overrides)
|
81
80
|
params.merge!(action: "docs.index", rest_api: "index")
|
@@ -101,7 +100,7 @@ module Elastomer
|
|
101
100
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete.html
|
102
101
|
#
|
103
102
|
# Returns the response body as a Hash
|
104
|
-
def delete(
|
103
|
+
def delete(params = {})
|
105
104
|
response = client.delete "/{index}/{type}/{id}", update_params(params, action: "docs.delete", rest_api: "delete")
|
106
105
|
response.body
|
107
106
|
end
|
@@ -115,7 +114,7 @@ module Elastomer
|
|
115
114
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html#docs-get
|
116
115
|
#
|
117
116
|
# Returns the response body as a Hash
|
118
|
-
def get(
|
117
|
+
def get(params = {})
|
119
118
|
response = client.get "/{index}/{type}/{id}", update_params(params, action: "docs.get", rest_api: "get")
|
120
119
|
response.body
|
121
120
|
end
|
@@ -129,7 +128,7 @@ module Elastomer
|
|
129
128
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html#docs-get
|
130
129
|
#
|
131
130
|
# Returns true if the document exists
|
132
|
-
def exists?(
|
131
|
+
def exists?(params = {})
|
133
132
|
response = client.head "/{index}/{type}/{id}", update_params(params, action: "docs.exists", rest_api: "exists")
|
134
133
|
response.success?
|
135
134
|
end
|
@@ -144,7 +143,7 @@ module Elastomer
|
|
144
143
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html#_source
|
145
144
|
#
|
146
145
|
# Returns the response body as a Hash
|
147
|
-
def source(
|
146
|
+
def source(params = {})
|
148
147
|
response = client.get "/{index}/{type}/{id}/_source", update_params(params, action: "docs.source", rest_api: "get_source")
|
149
148
|
response.body
|
150
149
|
end
|
@@ -157,11 +156,11 @@ module Elastomer
|
|
157
156
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.html
|
158
157
|
#
|
159
158
|
# Returns the response body as a Hash
|
160
|
-
def multi_get(
|
159
|
+
def multi_get(body, params = {})
|
161
160
|
overrides = from_document body
|
162
161
|
overrides.merge!(action: "docs.multi_get", rest_api: "mget")
|
163
162
|
|
164
|
-
response = client.get "{/index}{/type}/_mget", update_params(params, overrides)
|
163
|
+
response = client.get "{/index}{/type}/_mget", update_params(params, overrides, client.version_support.es_version_8_plus?)
|
165
164
|
response.body
|
166
165
|
end
|
167
166
|
alias_method :mget, :multi_get
|
@@ -174,11 +173,15 @@ module Elastomer
|
|
174
173
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html
|
175
174
|
#
|
176
175
|
# Returns the response body as a Hash
|
177
|
-
def update(
|
176
|
+
def update(script, params = {})
|
178
177
|
overrides = from_document script
|
179
178
|
overrides.merge!(action: "docs.update", rest_api: "update")
|
180
179
|
|
181
|
-
|
180
|
+
if client.version_support.es_version_8_plus?
|
181
|
+
response = client.post "/{index}/_update/{id}", update_params(params, overrides, true)
|
182
|
+
else
|
183
|
+
response = client.post "/{index}/{type}/{id}/_update", update_params(params, overrides)
|
184
|
+
end
|
182
185
|
response.body
|
183
186
|
end
|
184
187
|
|
@@ -204,10 +207,10 @@ module Elastomer
|
|
204
207
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html
|
205
208
|
#
|
206
209
|
# Returns the response body as a hash
|
207
|
-
def search(
|
210
|
+
def search(query, params = nil)
|
208
211
|
query, params = extract_params(query) if params.nil?
|
209
212
|
|
210
|
-
response = client.get "/{index}{/type}/_search", update_params(params, body: query, action: "docs.search", rest_api: "search")
|
213
|
+
response = client.get "/{index}{/type}/_search", update_params(params, {body: query, action: "docs.search", rest_api: "search"}, client.version_support.es_version_8_plus?)
|
211
214
|
response.body
|
212
215
|
end
|
213
216
|
|
@@ -224,8 +227,10 @@ module Elastomer
|
|
224
227
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/search-shards.html
|
225
228
|
#
|
226
229
|
# Returns the response body as a hash
|
227
|
-
def search_shards(
|
228
|
-
|
230
|
+
def search_shards(params = {})
|
231
|
+
updated_params = update_params(params, { action: "docs.search_shards", rest_api: "search_shards" }, true)
|
232
|
+
|
233
|
+
response = client.get "/{index}/_search_shards", updated_params
|
229
234
|
response.body
|
230
235
|
end
|
231
236
|
|
@@ -249,36 +254,20 @@ module Elastomer
|
|
249
254
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/search-count.html
|
250
255
|
#
|
251
256
|
# Returns the response body as a Hash
|
252
|
-
def count(
|
257
|
+
def count(query, params = nil)
|
253
258
|
query, params = extract_params(query) if params.nil?
|
254
259
|
|
255
|
-
|
260
|
+
if client.version_support.es_version_8_plus?
|
261
|
+
response = client.get "/{index}/_count", update_params(params, {body: query, action: "docs.count", rest_api: "count"}, true)
|
262
|
+
else
|
263
|
+
response = client.get "/{index}{/type}/_count", update_params(params, body: query, action: "docs.count", rest_api: "count")
|
264
|
+
end
|
256
265
|
response.body
|
257
266
|
end
|
258
267
|
|
259
|
-
# Delete documents by query
|
260
|
-
# application-level delete by query method.
|
261
|
-
#
|
262
|
-
# NOTE: The parameters and response format varies by version. To have more
|
263
|
-
# control over this, use app_delete_by_query or native_delete_by_query
|
264
|
-
# directly.
|
268
|
+
# Delete documents by query
|
265
269
|
def delete_by_query(query, params = nil)
|
266
|
-
send(
|
267
|
-
end
|
268
|
-
|
269
|
-
# DEPRECATED: Delete documents from one or more indices and one or more types based
|
270
|
-
# on a query. This method supports both the "request body" query and the
|
271
|
-
# "URI request" query. When using the request body semantics, the query
|
272
|
-
# hash must contain the :query key. Otherwise we assume a URI request is
|
273
|
-
# being made.
|
274
|
-
#
|
275
|
-
# See Client#app_delete_by_query for more information.
|
276
|
-
#
|
277
|
-
# Returns a Hash of statistics about the delete operations
|
278
|
-
def app_delete_by_query(query, params = nil)
|
279
|
-
query, params = extract_params(query) if params.nil?
|
280
|
-
|
281
|
-
@client.app_delete_by_query(query, update_params(params))
|
270
|
+
send(:native_delete_by_query, query, params)
|
282
271
|
end
|
283
272
|
|
284
273
|
# Delete documents from one or more indices and one or more types based
|
@@ -289,7 +278,7 @@ module Elastomer
|
|
289
278
|
# Returns a Hash of statistics about the delete operations as returned by
|
290
279
|
# _delete_by_query.
|
291
280
|
#
|
292
|
-
# Raises
|
281
|
+
# Raises ElastomerClient::Client::IncompatibleVersionException if this version
|
293
282
|
# of Elasticsearch does not support _delete_by_query.
|
294
283
|
def native_delete_by_query(query, params = {})
|
295
284
|
query, params = extract_params(query) if params.nil?
|
@@ -297,6 +286,18 @@ module Elastomer
|
|
297
286
|
@client.native_delete_by_query(query, update_params(params))
|
298
287
|
end
|
299
288
|
|
289
|
+
# Update documents by query using Elasticsearch's _update_by_query API.
|
290
|
+
#
|
291
|
+
# See Client#update_by_query for more information.
|
292
|
+
#
|
293
|
+
# Returns a Hash of statistics about the update operations as returned by
|
294
|
+
# _update_by_query.
|
295
|
+
def update_by_query(query, params = nil)
|
296
|
+
query, params = extract_params(query) if params.nil?
|
297
|
+
|
298
|
+
@client.update_by_query(query, update_params(params))
|
299
|
+
end
|
300
|
+
|
300
301
|
# Matches a provided or existing document to the stored percolator
|
301
302
|
# queries. To match an existing document, pass `nil` as the body and
|
302
303
|
# include `:id` in the params.
|
@@ -309,7 +310,7 @@ module Elastomer
|
|
309
310
|
#
|
310
311
|
# Returns the response body as a Hash
|
311
312
|
def percolate(body, params = {})
|
312
|
-
response = client.get "/{index}/{type}{/id}/_percolate", update_params(params, body
|
313
|
+
response = client.get "/{index}/{type}{/id}/_percolate", update_params(params, body:, action: "percolator.percolate", rest_api: "percolate")
|
313
314
|
response.body
|
314
315
|
end
|
315
316
|
|
@@ -325,7 +326,7 @@ module Elastomer
|
|
325
326
|
#
|
326
327
|
# Returns the count
|
327
328
|
def percolate_count(body, params = {})
|
328
|
-
response = client.get "/{index}/{type}{/id}/_percolate/count", update_params(params, body
|
329
|
+
response = client.get "/{index}/{type}{/id}/_percolate/count", update_params(params, body:, action: "percolator.percolate_count", rest_api: "count_percolate")
|
329
330
|
response.body["total"]
|
330
331
|
end
|
331
332
|
|
@@ -339,8 +340,12 @@ module Elastomer
|
|
339
340
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-termvectors.html
|
340
341
|
#
|
341
342
|
# Returns the response body as a hash
|
342
|
-
def termvector(
|
343
|
-
|
343
|
+
def termvector(params = {})
|
344
|
+
if client.version_support.es_version_8_plus?
|
345
|
+
response = client.get "/{index}/_termvectors/{id}", update_params(params, {action: "docs.termvector", rest_api: "termvectors"}, true)
|
346
|
+
else
|
347
|
+
response = client.get "/{index}/{type}/{id}/_termvectors", update_params(params, action: "docs.termvector", rest_api: "termvectors")
|
348
|
+
end
|
344
349
|
response.body
|
345
350
|
end
|
346
351
|
alias_method :termvectors, :termvector
|
@@ -357,15 +362,13 @@ module Elastomer
|
|
357
362
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-termvectors.html
|
358
363
|
#
|
359
364
|
# Returns the response body as a hash
|
360
|
-
def multi_termvectors(
|
361
|
-
response = client.get "{/index}{/type}/_mtermvectors", update_params(params, body
|
365
|
+
def multi_termvectors(body, params = {})
|
366
|
+
response = client.get "{/index}{/type}/_mtermvectors", update_params(params, {body:, action: "docs.multi_termvectors", rest_api: "mtermvectors"}, client.version_support.es_version_8_plus?)
|
362
367
|
response.body
|
363
368
|
end
|
364
369
|
alias_method :multi_term_vectors, :multi_termvectors
|
365
370
|
|
366
|
-
|
367
|
-
Percolate
|
368
|
-
=end
|
371
|
+
# Percolate
|
369
372
|
|
370
373
|
# Compute a score explanation for a query and a specific document. This
|
371
374
|
# can give useful feedback about why a document matched or didn't match
|
@@ -384,10 +387,14 @@ Percolate
|
|
384
387
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/search-explain.html
|
385
388
|
#
|
386
389
|
# Returns the response body as a hash
|
387
|
-
def explain(
|
390
|
+
def explain(query, params = nil)
|
388
391
|
query, params = extract_params(query) if params.nil?
|
389
392
|
|
390
|
-
|
393
|
+
if client.version_support.es_version_8_plus?
|
394
|
+
response = client.get "/{index}/_explain/{id}", update_params(params, {body: query, action: "docs.explain", rest_api: "explain"}, true)
|
395
|
+
else
|
396
|
+
response = client.get "/{index}/{type}/{id}/_explain", update_params(params, body: query, action: "docs.explain", rest_api: "explain")
|
397
|
+
end
|
391
398
|
response.body
|
392
399
|
end
|
393
400
|
|
@@ -409,10 +416,10 @@ Percolate
|
|
409
416
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/search-validate.html
|
410
417
|
#
|
411
418
|
# Returns the response body as a hash
|
412
|
-
def validate(
|
419
|
+
def validate(query, params = nil)
|
413
420
|
query, params = extract_params(query) if params.nil?
|
414
421
|
|
415
|
-
response = client.get "/{index}{/type}/_validate/query", update_params(params, body: query, action: "docs.validate", rest_api: "indices.validate_query")
|
422
|
+
response = client.get "/{index}{/type}/_validate/query", update_params(params, {body: query, action: "docs.validate", rest_api: "indices.validate_query"}, client.version_support.es_version_8_plus?)
|
416
423
|
response.body
|
417
424
|
end
|
418
425
|
|
@@ -437,7 +444,7 @@ Percolate
|
|
437
444
|
# end
|
438
445
|
#
|
439
446
|
# Returns the response body as a Hash
|
440
|
-
def bulk(
|
447
|
+
def bulk(params = {}, &block)
|
441
448
|
raise "a block is required" if block.nil?
|
442
449
|
|
443
450
|
params = {index: self.name, type: self.type}.merge params
|
@@ -465,8 +472,8 @@ Percolate
|
|
465
472
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html
|
466
473
|
#
|
467
474
|
# Returns a new Scroller instance
|
468
|
-
def scroll(
|
469
|
-
opts = {index: name, type:
|
475
|
+
def scroll(query, opts = {})
|
476
|
+
opts = {index: name, type:}.merge opts
|
470
477
|
client.scroll query, opts
|
471
478
|
end
|
472
479
|
|
@@ -492,8 +499,8 @@ Percolate
|
|
492
499
|
# end
|
493
500
|
#
|
494
501
|
# Returns a new Scroller instance
|
495
|
-
def scan(
|
496
|
-
opts = {index: name, type:
|
502
|
+
def scan(query, opts = {})
|
503
|
+
opts = {index: name, type:}.merge opts
|
497
504
|
client.scan query, opts
|
498
505
|
end
|
499
506
|
|
@@ -521,10 +528,11 @@ Percolate
|
|
521
528
|
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html
|
522
529
|
#
|
523
530
|
# Returns the response body as a Hash
|
524
|
-
def multi_search(
|
531
|
+
def multi_search(params = {}, &block)
|
525
532
|
raise "a block is required" if block.nil?
|
526
533
|
|
527
534
|
params = {index: self.name, type: self.type}.merge params
|
535
|
+
params.delete(:type) if client.version_support.es_version_8_plus?
|
528
536
|
client.multi_search params, &block
|
529
537
|
end
|
530
538
|
|
@@ -554,9 +562,9 @@ Percolate
|
|
554
562
|
end
|
555
563
|
|
556
564
|
SPECIAL_KEYS= %i[
|
557
|
-
index type id version version_type op_type routing parent
|
565
|
+
index type id version version_type op_type routing parent
|
558
566
|
consistency replication refresh wait_for_active_shards
|
559
|
-
].inject({}) { |h,k| h[k] = "_#{k}"; h }.freeze
|
567
|
+
].inject({}) { |h, k| h[k] = "_#{k}"; h }.freeze
|
560
568
|
|
561
569
|
# Internal: Given a `document` generate an options hash that will
|
562
570
|
# override parameters based on the content of the document. The document
|
@@ -569,9 +577,9 @@ Percolate
|
|
569
577
|
#
|
570
578
|
# Returns an options Hash extracted from the document.
|
571
579
|
#
|
572
|
-
# Raises
|
580
|
+
# Raises ElastomerClient::Client::IllegalArgument if an unsupported indexing
|
573
581
|
# directive is used.
|
574
|
-
def from_document(
|
582
|
+
def from_document(document)
|
575
583
|
opts = {body: document}
|
576
584
|
|
577
585
|
if document.is_a? Hash
|
@@ -591,16 +599,18 @@ Percolate
|
|
591
599
|
# overrides - Optional parameter overrides as a Hash
|
592
600
|
#
|
593
601
|
# Returns a new params Hash.
|
594
|
-
def update_params(
|
602
|
+
def update_params(params, overrides = nil, delete_type = false)
|
595
603
|
h = defaults.update params
|
596
604
|
h.update overrides unless overrides.nil?
|
597
|
-
h[:routing] = h[:routing].join(",") if
|
605
|
+
h[:routing] = h[:routing].join(",") if h[:routing].is_a?(Array)
|
606
|
+
h[:type] = "_doc" if client.version_support.es_version_8_plus? && !delete_type
|
607
|
+
h.delete(:type) if delete_type
|
598
608
|
h
|
599
609
|
end
|
600
610
|
|
601
611
|
# Internal: Returns a Hash containing default parameters.
|
602
612
|
def defaults
|
603
|
-
{ index: name, type:
|
613
|
+
{ index: name, type: }
|
604
614
|
end
|
605
615
|
|
606
616
|
# Internal: Allow params to be passed as the first argument to
|
@@ -610,7 +620,7 @@ Percolate
|
|
610
620
|
# params - params hash OR nil if no query
|
611
621
|
#
|
612
622
|
# Returns an array of the query (possibly nil) and params Hash.
|
613
|
-
def extract_params(
|
623
|
+
def extract_params(query, params = nil)
|
614
624
|
if params.nil?
|
615
625
|
if query.key? :query
|
616
626
|
params = {}
|
@@ -1,13 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
|
-
module
|
3
|
+
module ElastomerClient
|
3
4
|
|
4
|
-
# Parent class for all
|
5
|
+
# Parent class for all ElastomerClient errors.
|
5
6
|
Error = Class.new StandardError
|
6
7
|
|
7
8
|
class Client
|
8
9
|
|
9
10
|
# General error response from client requests.
|
10
|
-
class Error < ::
|
11
|
+
class Error < ::ElastomerClient::Error
|
11
12
|
|
12
13
|
# Construct a new Error from the given response object or a message
|
13
14
|
# String. If a response object is given, the error message will be
|
@@ -15,7 +16,7 @@ module Elastomer
|
|
15
16
|
#
|
16
17
|
# response - Faraday::Response object or a simple error message String
|
17
18
|
#
|
18
|
-
def initialize(
|
19
|
+
def initialize(*args)
|
19
20
|
@status = nil
|
20
21
|
@error = nil
|
21
22
|
|
@@ -33,10 +34,10 @@ module Elastomer
|
|
33
34
|
@error = body["error"] if body.is_a?(Hash) && body.key?("error")
|
34
35
|
|
35
36
|
message = @error || body.to_s
|
36
|
-
super
|
37
|
+
super(message)
|
37
38
|
|
38
39
|
else
|
39
|
-
super
|
40
|
+
super(args.join(" "))
|
40
41
|
end
|
41
42
|
end
|
42
43
|
|
@@ -96,17 +97,6 @@ module Elastomer
|
|
96
97
|
ConnectionFailed.fatal = false
|
97
98
|
RejectedExecutionError.fatal = false
|
98
99
|
|
99
|
-
# Define an Elastomer::Client exception class on the fly for
|
100
|
-
# Faraday exception classes that we don't specifically wrap.
|
101
|
-
Faraday::Error.constants.each do |error_name|
|
102
|
-
next if ::Elastomer::Client.const_get(error_name) rescue nil
|
103
|
-
|
104
|
-
error_class = Faraday::Error.const_get(error_name)
|
105
|
-
next unless error_class < Faraday::Error::ClientError
|
106
|
-
|
107
|
-
::Elastomer::Client.const_set(error_name, Class.new(Error))
|
108
|
-
end
|
109
|
-
|
110
100
|
# Exception for operations that are unsupported with the version of
|
111
101
|
# Elasticsearch being used.
|
112
102
|
IncompatibleVersionException = Class.new Error
|