elastomer-client 3.2.2 → 6.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/.devcontainer/devcontainer.json +46 -0
  3. data/.devcontainer/postCreateCommand.sh +4 -0
  4. data/.github/dependabot.yaml +11 -0
  5. data/.github/workflows/main.yml +45 -0
  6. data/.github/workflows/rubocop.yml +15 -0
  7. data/.gitignore +1 -1
  8. data/.rubocop.yml +13 -65
  9. data/.ruby-version +1 -0
  10. data/CHANGELOG.md +76 -0
  11. data/Gemfile +18 -1
  12. data/README.md +110 -51
  13. data/Rakefile +3 -1
  14. data/docker/compose.yaml +71 -0
  15. data/docker/elasticsearch8plus.yml +13 -0
  16. data/docs/README.md +4 -5
  17. data/docs/bulk_indexing.md +1 -1
  18. data/docs/client.md +20 -33
  19. data/docs/cluster.md +8 -8
  20. data/docs/docs.md +5 -5
  21. data/docs/index.md +4 -4
  22. data/docs/multi_search.md +1 -1
  23. data/docs/notifications.md +3 -3
  24. data/docs/scan_scroll.md +1 -1
  25. data/docs/snapshots.md +1 -1
  26. data/docs/templates.md +1 -1
  27. data/elastomer-client.gemspec +7 -16
  28. data/lib/{elastomer → elastomer_client}/client/bulk.rb +70 -47
  29. data/lib/{elastomer → elastomer_client}/client/cluster.rb +18 -16
  30. data/lib/{elastomer → elastomer_client}/client/delete_by_query.rb +6 -4
  31. data/lib/{elastomer → elastomer_client}/client/docs.rb +82 -72
  32. data/lib/{elastomer → elastomer_client}/client/errors.rb +7 -17
  33. data/lib/{elastomer → elastomer_client}/client/index.rb +55 -79
  34. data/lib/{elastomer → elastomer_client}/client/multi_percolate.rb +7 -5
  35. data/lib/{elastomer → elastomer_client}/client/multi_search.rb +5 -3
  36. data/lib/{elastomer → elastomer_client}/client/native_delete_by_query.rb +6 -6
  37. data/lib/{elastomer → elastomer_client}/client/nodes.rb +11 -10
  38. data/lib/{elastomer → elastomer_client}/client/percolator.rb +9 -10
  39. data/lib/elastomer_client/client/reindex.rb +29 -0
  40. data/lib/{elastomer → elastomer_client}/client/repository.rb +7 -5
  41. data/lib/{elastomer → elastomer_client}/client/rest_api_spec/api_spec.rb +7 -6
  42. data/lib/{elastomer → elastomer_client}/client/rest_api_spec/api_spec_v5_6.rb +1 -1
  43. data/lib/elastomer_client/client/rest_api_spec/api_spec_v8_13.rb +7567 -0
  44. data/lib/elastomer_client/client/rest_api_spec/api_spec_v8_7.rb +6553 -0
  45. data/lib/{elastomer → elastomer_client}/client/rest_api_spec/rest_api.rb +6 -4
  46. data/lib/{elastomer → elastomer_client}/client/rest_api_spec.rb +3 -2
  47. data/lib/{elastomer → elastomer_client}/client/scroller.rb +17 -16
  48. data/lib/{elastomer → elastomer_client}/client/snapshot.rb +10 -8
  49. data/lib/{elastomer → elastomer_client}/client/tasks.rb +9 -13
  50. data/lib/{elastomer → elastomer_client}/client/template.rb +10 -9
  51. data/lib/elastomer_client/client/update_by_query.rb +50 -0
  52. data/lib/{elastomer → elastomer_client}/client.rb +51 -62
  53. data/lib/{elastomer → elastomer_client}/core_ext/time.rb +2 -0
  54. data/lib/{elastomer → elastomer_client}/middleware/compress.rb +2 -2
  55. data/lib/{elastomer → elastomer_client}/middleware/encode_json.rb +4 -2
  56. data/lib/{elastomer → elastomer_client}/middleware/limit_size.rb +5 -3
  57. data/lib/{elastomer → elastomer_client}/middleware/opaque_id.rb +10 -7
  58. data/lib/{elastomer → elastomer_client}/middleware/parse_json.rb +5 -3
  59. data/lib/{elastomer → elastomer_client}/notifications.rb +17 -15
  60. data/lib/elastomer_client/version.rb +9 -0
  61. data/lib/elastomer_client/version_support.rb +24 -0
  62. data/script/bootstrap +4 -2
  63. data/script/console +3 -1
  64. data/script/generate-rest-api-spec +77 -22
  65. data/test/assertions.rb +32 -39
  66. data/test/client/bulk_test.rb +165 -143
  67. data/test/client/cluster_test.rb +35 -13
  68. data/test/client/docs_test.rb +387 -274
  69. data/test/client/errors_test.rb +38 -40
  70. data/test/client/index_test.rb +243 -202
  71. data/test/client/multi_percolate_test.rb +46 -41
  72. data/test/client/multi_search_test.rb +122 -67
  73. data/test/client/native_delete_by_query_test.rb +96 -88
  74. data/test/client/nodes_test.rb +21 -10
  75. data/test/client/percolator_test.rb +19 -14
  76. data/test/client/reindex_test.rb +76 -0
  77. data/test/client/repository_test.rb +31 -19
  78. data/test/client/rest_api_spec/api_spec_test.rb +13 -11
  79. data/test/client/rest_api_spec/rest_api_test.rb +9 -7
  80. data/test/client/scroller_test.rb +44 -70
  81. data/test/client/snapshot_test.rb +38 -21
  82. data/test/client/stubbed_client_test.rb +7 -4
  83. data/test/client/tasks_test.rb +12 -17
  84. data/test/client/template_test.rb +34 -13
  85. data/test/client/update_by_query_test.rb +137 -0
  86. data/test/client_test.rb +158 -92
  87. data/test/core_ext/time_test.rb +14 -12
  88. data/test/middleware/encode_json_test.rb +18 -7
  89. data/test/middleware/opaque_id_test.rb +18 -14
  90. data/test/middleware/parse_json_test.rb +17 -9
  91. data/test/mock_response.rb +30 -0
  92. data/test/notifications_test.rb +15 -8
  93. data/test/test_helper.rb +40 -97
  94. data/test/version_support_test.rb +13 -78
  95. metadata +60 -208
  96. data/.overcommit.yml +0 -5
  97. data/.travis.yml +0 -34
  98. data/docker/docker-compose.cibuild.yml +0 -8
  99. data/docker/docker-compose.es24.yml +0 -34
  100. data/docker/docker-compose.es56.yml +0 -37
  101. data/docs/warmers.md +0 -3
  102. data/lib/elastomer/client/app_delete_by_query.rb +0 -144
  103. data/lib/elastomer/client/rest_api_spec/api_spec_v2_3.rb +0 -2232
  104. data/lib/elastomer/client/rest_api_spec/api_spec_v2_4.rb +0 -2250
  105. data/lib/elastomer/client/warmer.rb +0 -98
  106. data/lib/elastomer/version.rb +0 -7
  107. data/lib/elastomer/version_support.rb +0 -182
  108. data/script/cibuild +0 -103
  109. data/script/cibuild-elastomer-client +0 -1
  110. data/script/cibuild-elastomer-client-es24 +0 -8
  111. data/script/cibuild-elastomer-client-es56 +0 -8
  112. data/test/client/app_delete_by_query_test.rb +0 -192
  113. data/test/client/es_5_x_warmer_test.rb +0 -13
  114. data/test/client/warmer_test.rb +0 -60
@@ -1,4 +1,6 @@
1
- module Elastomer
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 - Elastomer::Client used for HTTP requests to the server
16
+ # client - ElastomerClient::Client used for HTTP requests to the server
15
17
  #
16
- def initialize( client )
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( params = {} )
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( params = {} )
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( params = {} )
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( params = {} )
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( params = {} )
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( body, params = {} )
120
- response = client.put "/_cluster/settings", params.merge(body: body, action: "cluster.update_settings", rest_api: "cluster.put_settings")
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( commands, params = {} )
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: body, action: "cluster.reroute", rest_api: "cluster.reroute")
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( params = {} )
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( actions, params = {} )
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: body, action: "cluster.update_aliases", rest_api: "indices.update_aliases")
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
- module Elastomer
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 Elastomer::Client#native_delete_by_query
8
- # or Elastomer::Client#app_delete_by_query directly.
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(version_support.delete_by_query_method, query, params)
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 Elastomer
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( name = nil, type = nil )
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 - Elastomer::Client used for HTTP requests to the server
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( client, name, type = nil )
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 Elastomer::Client::IllegalArgument if an unsupported indexing
75
+ # Raises ElastomerClient::Client::IllegalArgument if an unsupported indexing
77
76
  # directive is used.
78
- def index( document, params = {} )
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( params = {} )
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( params = {} )
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?( params = {} )
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( params = {} )
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( body, params = {} )
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( script, params = {} )
176
+ def update(script, params = {})
178
177
  overrides = from_document script
179
178
  overrides.merge!(action: "docs.update", rest_api: "update")
180
179
 
181
- response = client.post "/{index}/{type}/{id}/_update", update_params(params, overrides)
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( query, params = nil )
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( params = {} )
228
- response = client.get "/{index}{/type}/_search_shards", update_params(params, action: "docs.search_shards", rest_api: "search_shards")
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( query, params = nil )
257
+ def count(query, params = nil)
253
258
  query, params = extract_params(query) if params.nil?
254
259
 
255
- response = client.get "/{index}{/type}/_count", update_params(params, body: query, action: "docs.count", rest_api: "count")
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 following either the native or
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(@client.version_support.delete_by_query_method, query, params)
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 Elastomer::Client::IncompatibleVersionException if this version
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: body, action: "percolator.percolate", rest_api: "percolate")
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: body, action: "percolator.percolate_count", rest_api: "count_percolate")
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( params = {} )
343
- response = client.get "/{index}/{type}/{id}/_termvectors", update_params(params, action: "docs.termvector", rest_api: "termvectors")
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( body, params = {} )
361
- response = client.get "{/index}{/type}/_mtermvectors", update_params(params, body: body, action: "docs.multi_termvectors", rest_api: "mtermvectors")
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
- =begin
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( query, params = nil )
390
+ def explain(query, params = nil)
388
391
  query, params = extract_params(query) if params.nil?
389
392
 
390
- response = client.get "/{index}/{type}/{id}/_explain", update_params(params, body: query, action: "docs.explain", rest_api: "explain")
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( query, params = nil )
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( params = {}, &block )
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( query, opts = {} )
469
- opts = {index: name, type: type}.merge opts
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( query, opts = {} )
496
- opts = {index: name, type: type}.merge opts
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( params = {}, &block )
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 timestamp ttl
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 Elastomer::Client::IllegalArgument if an unsupported indexing
580
+ # Raises ElastomerClient::Client::IllegalArgument if an unsupported indexing
573
581
  # directive is used.
574
- def from_document( 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( params, overrides = nil )
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 Array === h[:routing]
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: 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( query, params = nil )
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 Elastomer
3
+ module ElastomerClient
3
4
 
4
- # Parent class for all Elastomer errors.
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 < ::Elastomer::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( *args )
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 message
37
+ super(message)
37
38
 
38
39
  else
39
- super args.join(" ")
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