elastomer-client 3.2.3 → 6.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.devcontainer/devcontainer.json +46 -0
- data/.devcontainer/postCreateCommand.sh +4 -0
- data/.github/dependabot.yaml +11 -0
- data/.github/workflows/main.yml +45 -0
- data/.github/workflows/rubocop.yml +15 -0
- data/.gitignore +1 -1
- data/.rubocop.yml +13 -65
- data/.ruby-version +1 -0
- data/CHANGELOG.md +76 -0
- data/Gemfile +18 -1
- data/README.md +110 -51
- data/Rakefile +3 -1
- data/docker/compose.yaml +71 -0
- data/docker/elasticsearch8plus.yml +13 -0
- data/docs/README.md +4 -5
- data/docs/bulk_indexing.md +1 -1
- data/docs/client.md +20 -33
- data/docs/cluster.md +8 -8
- data/docs/docs.md +5 -5
- data/docs/index.md +4 -4
- data/docs/multi_search.md +1 -1
- data/docs/notifications.md +3 -3
- data/docs/scan_scroll.md +1 -1
- data/docs/snapshots.md +1 -1
- data/docs/templates.md +1 -1
- data/elastomer-client.gemspec +7 -16
- data/lib/{elastomer → elastomer_client}/client/bulk.rb +70 -47
- data/lib/{elastomer → elastomer_client}/client/cluster.rb +18 -16
- data/lib/{elastomer → elastomer_client}/client/delete_by_query.rb +6 -4
- data/lib/{elastomer → elastomer_client}/client/docs.rb +82 -72
- data/lib/{elastomer → elastomer_client}/client/errors.rb +7 -17
- data/lib/{elastomer → elastomer_client}/client/index.rb +55 -79
- data/lib/{elastomer → elastomer_client}/client/multi_percolate.rb +7 -5
- data/lib/{elastomer → elastomer_client}/client/multi_search.rb +5 -3
- data/lib/{elastomer → elastomer_client}/client/native_delete_by_query.rb +6 -6
- data/lib/{elastomer → elastomer_client}/client/nodes.rb +11 -10
- data/lib/{elastomer → elastomer_client}/client/percolator.rb +9 -10
- data/lib/elastomer_client/client/reindex.rb +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,54 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require File.expand_path("../../test_helper", __FILE__)
|
2
4
|
|
3
|
-
describe
|
4
|
-
let(:middleware) {
|
5
|
+
describe ElastomerClient::Middleware::ParseJson do
|
6
|
+
let(:middleware) { ElastomerClient::Middleware::ParseJson.new(lambda { |env| Faraday::Response.new(env) }) }
|
5
7
|
let(:headers) { Hash.new }
|
6
8
|
|
7
9
|
def process(body, content_type = nil)
|
8
|
-
env = {
|
10
|
+
env = { body:, response_headers: Faraday::Utils::Headers.new(headers) }
|
9
11
|
env[:response_headers]["content-type"] = content_type if content_type
|
10
12
|
middleware.call(env)
|
11
13
|
end
|
12
14
|
|
13
15
|
it "doesn't change nil body" do
|
14
16
|
response = process(nil)
|
17
|
+
|
15
18
|
assert_nil response.body
|
16
19
|
end
|
17
20
|
|
18
21
|
it "nullifies empty body" do
|
19
22
|
response = process("")
|
23
|
+
|
20
24
|
assert_nil response.body
|
21
25
|
end
|
22
26
|
|
23
27
|
it "nullifies blank body" do
|
24
28
|
response = process(" ")
|
29
|
+
|
25
30
|
assert_nil response.body
|
26
31
|
end
|
27
32
|
|
28
33
|
it "parses json body with empty type" do
|
29
34
|
response = process('{"a":1}')
|
35
|
+
|
30
36
|
assert_equal({"a" => 1}, response.body)
|
31
37
|
end
|
32
38
|
|
33
39
|
it "parses json body of correct type" do
|
34
40
|
response = process('{"a":1}', "application/json; charset=utf-8")
|
41
|
+
|
35
42
|
assert_equal({"a" => 1}, response.body)
|
36
43
|
end
|
37
44
|
|
38
45
|
it "ignores json body if incorrect type" do
|
39
46
|
response = process('{"a":1}', "application/xml; charset=utf-8")
|
47
|
+
|
40
48
|
assert_equal('{"a":1}', response.body)
|
41
49
|
end
|
42
50
|
|
43
51
|
it "chokes on invalid json" do
|
44
|
-
assert_raises(Faraday::
|
45
|
-
assert_raises(Faraday::
|
52
|
+
assert_raises(Faraday::ParsingError) { process "{!" }
|
53
|
+
assert_raises(Faraday::ParsingError) { process "invalid" }
|
46
54
|
|
47
55
|
# surprisingly these are all valid according to MultiJson
|
48
56
|
#
|
49
|
-
# assert_raises(Faraday::
|
50
|
-
# assert_raises(Faraday::
|
51
|
-
# assert_raises(Faraday::
|
52
|
-
# assert_raises(Faraday::
|
57
|
+
# assert_raises(Faraday::ParsingError) { process '"a"' }
|
58
|
+
# assert_raises(Faraday::ParsingError) { process 'true' }
|
59
|
+
# assert_raises(Faraday::ParsingError) { process 'null' }
|
60
|
+
# assert_raises(Faraday::ParsingError) { process '1' }
|
53
61
|
end
|
54
62
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ElastomerClient
|
4
|
+
module Middleware
|
5
|
+
class MockResponse < Faraday::Middleware
|
6
|
+
def initialize(app, &block)
|
7
|
+
super(app)
|
8
|
+
@response_block = block
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
env.clear_body if env.needs_body?
|
13
|
+
|
14
|
+
env.status = 200
|
15
|
+
env.response_headers = ::Faraday::Utils::Headers.new
|
16
|
+
env.response_headers["Fake"] = "yes"
|
17
|
+
env.response = ::Faraday::Response.new
|
18
|
+
|
19
|
+
@response_block&.call(env)
|
20
|
+
|
21
|
+
env.response.finish(env) unless env.parallel?
|
22
|
+
|
23
|
+
env.response
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
Faraday::Request.register_middleware \
|
30
|
+
mock_response: ElastomerClient::Middleware::MockResponse
|
data/test/notifications_test.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require File.expand_path("../test_helper", __FILE__)
|
2
|
-
require "
|
4
|
+
require "elastomer_client/notifications"
|
3
5
|
|
4
|
-
describe
|
6
|
+
describe ElastomerClient::Notifications do
|
5
7
|
before do
|
6
8
|
@name = "elastomer-notifications-test"
|
7
9
|
@index = $client.index @name
|
@@ -18,11 +20,12 @@ describe Elastomer::Notifications do
|
|
18
20
|
end
|
19
21
|
|
20
22
|
it "instruments timeouts" do
|
21
|
-
$client.stub :connection, lambda { raise Faraday::
|
22
|
-
assert_raises(
|
23
|
+
$client.stub :connection, lambda { raise Faraday::TimeoutError } do
|
24
|
+
assert_raises(ElastomerClient::Client::TimeoutError) { $client.info }
|
23
25
|
event = @events.detect { |e| e.payload[:action] == "cluster.info" }
|
24
26
|
exception = event.payload[:exception]
|
25
|
-
|
27
|
+
|
28
|
+
assert_equal "ElastomerClient::Client::TimeoutError", exception[0]
|
26
29
|
assert_match "timeout", exception[1]
|
27
30
|
end
|
28
31
|
end
|
@@ -42,11 +45,13 @@ describe Elastomer::Notifications do
|
|
42
45
|
it "instruments index actions" do
|
43
46
|
@index.exists?; assert_action_event("index.exists")
|
44
47
|
@index.create(default_index_settings)
|
48
|
+
|
45
49
|
assert_action_event("index.create")
|
46
50
|
wait_for_index(@index.name)
|
47
51
|
|
48
52
|
@index.get_settings; assert_action_event("index.get_settings")
|
49
53
|
@index.update_settings(number_of_replicas: 0)
|
54
|
+
|
50
55
|
assert_action_event("index.get_settings")
|
51
56
|
wait_for_index(@index.name)
|
52
57
|
|
@@ -58,6 +63,7 @@ describe Elastomer::Notifications do
|
|
58
63
|
it "includes the response body in the payload" do
|
59
64
|
@index.create(default_index_settings)
|
60
65
|
event = @events.detect { |e| e.payload[:action] == "index.create" }
|
66
|
+
|
61
67
|
assert event.payload[:response_body]
|
62
68
|
end
|
63
69
|
|
@@ -66,6 +72,7 @@ describe Elastomer::Notifications do
|
|
66
72
|
event = @events.detect { |e| e.payload[:action] == "index.create" }
|
67
73
|
|
68
74
|
payload = event.payload
|
75
|
+
|
69
76
|
assert payload[:response_body]
|
70
77
|
assert payload[:request_body]
|
71
78
|
assert_same payload[:body], payload[:request_body]
|
@@ -75,10 +82,10 @@ describe Elastomer::Notifications do
|
|
75
82
|
assert @events.detect { |e| e.payload[:action] == action }, "expected #{action} event"
|
76
83
|
end
|
77
84
|
|
78
|
-
def stub_client(method, url, status=200, body='{"acknowledged":true}')
|
85
|
+
def stub_client(method, url, status = 200, body = '{"acknowledged":true}')
|
79
86
|
stubs = Faraday::Adapter::Test::Stubs.new do |stub|
|
80
|
-
stub.send(method, url) { |env| [status, {}, body]}
|
87
|
+
stub.send(method, url) { |env| [status, {}, body] }
|
81
88
|
end
|
82
|
-
|
89
|
+
ElastomerClient::Client.new($client_params.merge(opaque_id: false, adapter: [:test, stubs]))
|
83
90
|
end
|
84
91
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "rubygems" unless defined? Gem
|
2
4
|
require "bundler"
|
3
5
|
Bundler.require(:default, :development)
|
@@ -21,11 +23,11 @@ require "minitest/focus"
|
|
21
23
|
|
22
24
|
# used in a couple test files, makes them available for all
|
23
25
|
require "active_support/core_ext/enumerable"
|
24
|
-
require
|
26
|
+
require "active_support/core_ext/hash"
|
25
27
|
|
26
28
|
# push the lib folder onto the load path
|
27
29
|
$LOAD_PATH.unshift "lib"
|
28
|
-
require "
|
30
|
+
require "elastomer_client/client"
|
29
31
|
|
30
32
|
# we are going to use the same client instance everywhere!
|
31
33
|
# the client should always be stateless
|
@@ -34,28 +36,18 @@ $client_params = {
|
|
34
36
|
read_timeout: 10,
|
35
37
|
open_timeout: 1,
|
36
38
|
opaque_id: false,
|
37
|
-
strict_params: true
|
39
|
+
strict_params: true,
|
40
|
+
compress_body: true
|
38
41
|
}
|
39
|
-
$client =
|
42
|
+
$client = ElastomerClient::Client.new(**$client_params)
|
40
43
|
|
41
44
|
# ensure we have an Elasticsearch server to test with
|
42
45
|
raise "No server available at #{$client.url}" unless $client.available?
|
43
46
|
|
44
47
|
puts "Elasticsearch version is #{$client.version}"
|
45
48
|
|
46
|
-
# COMPATIBILITY
|
47
|
-
# Returns true if the Elasticsearch cluster defaults to supporting compression.
|
48
|
-
def supports_compressed_bodies_by_default?
|
49
|
-
$client.version_support.es_version_5_x?
|
50
|
-
end
|
51
|
-
|
52
|
-
# Now that we have the version, re-create the client with compression if supported.
|
53
|
-
if supports_compressed_bodies_by_default?
|
54
|
-
$client = Elastomer::Client.new $client_params.merge(compress_body: true)
|
55
|
-
end
|
56
|
-
|
57
49
|
# remove any lingering test indices from the cluster
|
58
|
-
|
50
|
+
Minitest.after_run do
|
59
51
|
$client.cluster.indices.keys.each do |name|
|
60
52
|
next unless name =~ /^elastomer-/i
|
61
53
|
$client.index(name).delete
|
@@ -70,7 +62,7 @@ end
|
|
70
62
|
# add custom assertions
|
71
63
|
require File.expand_path("../assertions", __FILE__)
|
72
64
|
|
73
|
-
# require '
|
65
|
+
# require 'elastomer_client/notifications'
|
74
66
|
# require 'pp'
|
75
67
|
|
76
68
|
# ActiveSupport::Notifications.subscribe('request.client.elastomer') do |name, start_time, end_time, transaction_id, payload|
|
@@ -91,13 +83,13 @@ require File.expand_path("../assertions", __FILE__)
|
|
91
83
|
# setting of 1 replica.
|
92
84
|
#
|
93
85
|
# Returns the cluster health response.
|
94
|
-
# Raises
|
86
|
+
# Raises ElastomerClient::Client::TimeoutError if requested status is not achieved
|
95
87
|
# within 5 seconds.
|
96
|
-
def wait_for_index(name, status="yellow")
|
88
|
+
def wait_for_index(name, status = "yellow")
|
97
89
|
$client.cluster.health(
|
98
|
-
:
|
99
|
-
:
|
100
|
-
:
|
90
|
+
index: name,
|
91
|
+
wait_for_status: status,
|
92
|
+
timeout: "5s"
|
101
93
|
)
|
102
94
|
end
|
103
95
|
|
@@ -110,7 +102,7 @@ def run_snapshot_tests?
|
|
110
102
|
begin
|
111
103
|
create_repo("elastomer-client-snapshot-test")
|
112
104
|
$run_snapshot_tests = true
|
113
|
-
rescue
|
105
|
+
rescue ElastomerClient::Client::Error
|
114
106
|
puts "Could not create a snapshot repo. Snapshot tests will be disabled."
|
115
107
|
puts "To enable snapshot tests, add a path.repo setting to your elasticsearch.yml file."
|
116
108
|
$run_snapshot_tests = false
|
@@ -123,7 +115,7 @@ end
|
|
123
115
|
|
124
116
|
def create_repo(name, settings = {})
|
125
117
|
location = File.join(*[ENV["SNAPSHOT_DIR"], name].compact)
|
126
|
-
default_settings = {:
|
118
|
+
default_settings = {type: "fs", settings: {location:}}
|
127
119
|
$client.repository(name).create(default_settings.merge(settings))
|
128
120
|
end
|
129
121
|
|
@@ -153,7 +145,7 @@ def with_tmp_repo(name = SecureRandom.uuid, &block)
|
|
153
145
|
end
|
154
146
|
|
155
147
|
def create_snapshot(repo, name = SecureRandom.uuid)
|
156
|
-
repo.snapshot(name).create({}, :
|
148
|
+
repo.snapshot(name).create({}, wait_for_completion: true)
|
157
149
|
end
|
158
150
|
|
159
151
|
def with_tmp_snapshot(name = SecureRandom.uuid, &block)
|
@@ -180,9 +172,9 @@ def populate_background_index!(name)
|
|
180
172
|
docs.bulk do |d|
|
181
173
|
(1..500).each do |j|
|
182
174
|
d.index \
|
183
|
-
:
|
184
|
-
:
|
185
|
-
:
|
175
|
+
foo: "foo_#{i}_#{j}",
|
176
|
+
bar: "bar_#{i}_#{j}",
|
177
|
+
baz: "baz_#{i}_#{j}"
|
186
178
|
end
|
187
179
|
end
|
188
180
|
index.refresh
|
@@ -208,80 +200,31 @@ end
|
|
208
200
|
|
209
201
|
# The methods below are to support intention-revealing names about version
|
210
202
|
# differences in the tests. If necessary for general operation they can be moved
|
211
|
-
# into
|
212
|
-
|
213
|
-
# COMPATIBILITY
|
214
|
-
# ES 5.x returns `index` bulk request as `index` responses whether or not the
|
215
|
-
# document was created or updated. ES 2.x returns a `create` response if it was
|
216
|
-
# created.
|
217
|
-
def bulk_index_returns_create_for_new_documents?
|
218
|
-
$client.version_support.es_version_2_x?
|
219
|
-
end
|
203
|
+
# into ElastomerClient::VersionSupport.
|
220
204
|
|
221
205
|
# COMPATIBILITY
|
222
|
-
#
|
223
|
-
def
|
224
|
-
$client.version_support.
|
225
|
-
|
226
|
-
|
227
|
-
# COMPATIBILITY
|
228
|
-
# ES 2.x returns an empty result when an alias does not exist for a full or partial match
|
229
|
-
# ES 5.6 returns an error when an alias does not exist for a full or partial match
|
230
|
-
def fetching_non_existent_alias_returns_error?
|
231
|
-
$client.version_support.es_version_5_x?
|
232
|
-
end
|
233
|
-
|
234
|
-
# COMPATIBILITY
|
235
|
-
# ES 5.6 includes a _nodes key in the /_cluster/stats response. Strangely
|
236
|
-
# enough, this is not documented in the example response:
|
237
|
-
# https://www.elastic.co/guide/en/elasticsearch/reference/5.6/cluster-stats.html
|
238
|
-
def cluster_stats_includes_underscore_nodes?
|
239
|
-
$client.version_support.es_version_5_x?
|
240
|
-
end
|
241
|
-
|
242
|
-
# COMPATIBILITY
|
243
|
-
# ES 2.0 deprecated the `filtered` query type. ES 5.0 removed it entirely.
|
244
|
-
def filtered_query_removed?
|
245
|
-
$client.version_support.es_version_5_x?
|
246
|
-
end
|
247
|
-
|
248
|
-
# ES 5.6 percolator queries/document submissions require that an appropriate
|
249
|
-
# percolator type and field within that type are defined on the index mappings
|
250
|
-
def requires_percolator_mapping?
|
251
|
-
$client.version_support.es_version_5_x?
|
252
|
-
end
|
253
|
-
|
254
|
-
# COMPATIBILITY
|
255
|
-
# ES 5 removes the `output` option for fields.
|
256
|
-
# See: https://www.elastic.co/guide/en/elasticsearch/reference/5.6/breaking_50_suggester.html#_simpler_completion_indexing
|
257
|
-
def supports_suggest_output?
|
258
|
-
$client.version_support.es_version_2_x?
|
259
|
-
end
|
260
|
-
|
261
|
-
# COMPATIBILITY
|
262
|
-
# ES 5 returns information about the number of cleared scroll IDs
|
263
|
-
def returns_cleared_scroll_id_info?
|
264
|
-
$client.version_support.es_version_5_x?
|
265
|
-
end
|
266
|
-
|
267
|
-
# COMPATIBILITY
|
268
|
-
# Return a Hash with an unsupported indexing directive key/value to test fail-fast.
|
269
|
-
def incompatible_indexing_directive
|
270
|
-
if $client.version_support.es_version_2_x?
|
271
|
-
{_wait_for_active_shards: 10}
|
206
|
+
# ES8 drops mapping types, so don't wrap with a mapping type for ES8+
|
207
|
+
def mappings_wrapper(type, body, disable_all = false)
|
208
|
+
if $client.version_support.es_version_8_plus?
|
209
|
+
body
|
272
210
|
else
|
273
|
-
{
|
211
|
+
mapping = {
|
212
|
+
_default_: {
|
213
|
+
dynamic: "strict"
|
214
|
+
}
|
215
|
+
}
|
216
|
+
mapping[type] = body
|
217
|
+
if disable_all then mapping[type]["_all"] = { "enabled": false } end
|
218
|
+
mapping
|
274
219
|
end
|
275
220
|
end
|
276
221
|
|
277
222
|
# COMPATIBILITY
|
278
|
-
#
|
279
|
-
def
|
280
|
-
$client.version_support.
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
def supports_native_delete_by_query?
|
286
|
-
$client.version_support.native_delete_by_query?
|
223
|
+
# ES8 drops mapping types, so append type to the document only if ES version < 8
|
224
|
+
def document_wrapper(type, body)
|
225
|
+
if $client.version_support.es_version_8_plus?
|
226
|
+
body
|
227
|
+
else
|
228
|
+
body.merge({_type: type})
|
229
|
+
end
|
287
230
|
end
|
@@ -1,17 +1,19 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require_relative "test_helper"
|
4
|
+
|
5
|
+
describe ElastomerClient::VersionSupport do
|
4
6
|
describe "supported versions" do
|
5
|
-
it "allows
|
6
|
-
|
7
|
-
|
7
|
+
it "allows 5.0.0 to 8.x" do
|
8
|
+
five_series = ["5.0.0", "5.0.9", "5.1.0", "5.9.0", "5.99.100"]
|
9
|
+
eight_series = ["8.0.0", "8.0.9", "8.1.0", "8.9.0", "8.99.100"]
|
8
10
|
|
9
|
-
|
10
|
-
assert
|
11
|
+
five_series.each do |version|
|
12
|
+
assert ElastomerClient::VersionSupport.new(version)
|
11
13
|
end
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
+
eight_series.each do |version|
|
16
|
+
assert_predicate ElastomerClient::VersionSupport.new(version), :es_version_8_plus?
|
15
17
|
end
|
16
18
|
end
|
17
19
|
end
|
@@ -19,11 +21,11 @@ describe Elastomer::VersionSupport do
|
|
19
21
|
describe "unsupported versions" do
|
20
22
|
it "blow up" do
|
21
23
|
too_low = ["0.90", "1.0.1", "2.0.0", "2.2.0"]
|
22
|
-
too_high = ["
|
24
|
+
too_high = ["9.0.0"]
|
23
25
|
|
24
26
|
(too_low + too_high).each do |version|
|
25
27
|
exception = assert_raises(ArgumentError, "expected #{version} to not be supported") do
|
26
|
-
|
28
|
+
ElastomerClient::VersionSupport.new(version)
|
27
29
|
end
|
28
30
|
|
29
31
|
assert_match version, exception.message
|
@@ -31,71 +33,4 @@ describe Elastomer::VersionSupport do
|
|
31
33
|
end
|
32
34
|
end
|
33
35
|
end
|
34
|
-
|
35
|
-
describe "ES 2.x" do
|
36
|
-
let(:version_support) { Elastomer::VersionSupport.new("2.3.5") }
|
37
|
-
|
38
|
-
describe "#keyword" do
|
39
|
-
it "returns non_analyzed string" do
|
40
|
-
expected = {
|
41
|
-
type: "string",
|
42
|
-
index: "not_analyzed",
|
43
|
-
store: true
|
44
|
-
}
|
45
|
-
assert_equal(expected, version_support.keyword(store: true))
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe "#text" do
|
50
|
-
it "returns analyzed string" do
|
51
|
-
expected = {
|
52
|
-
type: "string",
|
53
|
-
term_vector: "with_positions_offsets"
|
54
|
-
}
|
55
|
-
assert_equal(expected, version_support.text(term_vector: "with_positions_offsets"))
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe "native_delete_by_query?" do
|
60
|
-
it "returns false" do
|
61
|
-
refute version_support.native_delete_by_query?, "ES 2.X does not have native delete_by_query support"
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
describe "ES 5.x" do
|
67
|
-
let(:version_support) { Elastomer::VersionSupport.new("5.6.0") }
|
68
|
-
|
69
|
-
describe "#keyword" do
|
70
|
-
it "returns keyword" do
|
71
|
-
expected = {
|
72
|
-
type: "keyword",
|
73
|
-
store: true
|
74
|
-
}
|
75
|
-
assert_equal(expected, version_support.keyword(store: true))
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
describe "#text" do
|
80
|
-
it "returns text" do
|
81
|
-
expected = {
|
82
|
-
type: "text",
|
83
|
-
term_vector: "with_positions_offsets"
|
84
|
-
}
|
85
|
-
assert_equal(expected, version_support.text(term_vector: "with_positions_offsets"))
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
describe "native_delete_by_query?" do
|
90
|
-
it "returns true" do
|
91
|
-
assert version_support.native_delete_by_query?, "ES 5.X has native delete_by_query support"
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
describe "#op_type_param" do
|
96
|
-
it "converts the supplied params key _op_type to op_type, if present" do
|
97
|
-
assert_equal(version_support.op_type(_op_type: "create"), {op_type: "create"})
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
36
|
end
|