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
data/test/client/nodes_test.rb
CHANGED
@@ -1,55 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative "../test_helper"
|
2
4
|
|
3
|
-
describe
|
5
|
+
describe ElastomerClient::Client::Nodes do
|
4
6
|
|
5
7
|
it "gets info for the node(s)" do
|
6
8
|
h = $client.nodes.info
|
9
|
+
|
7
10
|
assert h.key?("cluster_name"), "the cluster name is returned"
|
8
11
|
assert_instance_of Hash, h["nodes"], "the node list is returned"
|
9
12
|
end
|
10
13
|
|
11
14
|
it "gets stats for the node(s)" do
|
12
15
|
h = $client.nodes.stats
|
16
|
+
|
13
17
|
assert_instance_of Hash, h["nodes"], "the node list is returned"
|
14
18
|
|
15
19
|
node = h["nodes"].values.first
|
20
|
+
|
16
21
|
assert node.key?("indices"), "indices stats are returned"
|
17
22
|
end
|
18
23
|
|
19
24
|
it "filters node info" do
|
20
|
-
h = $client.nodes.info(:
|
25
|
+
h = $client.nodes.info(info: "os")
|
21
26
|
node = h["nodes"].values.first
|
27
|
+
|
22
28
|
assert node.key?("os"), "expected os info to be present"
|
23
|
-
|
29
|
+
refute node.key?("jvm"), "expected jvm info to be absent"
|
24
30
|
|
25
|
-
h = $client.nodes.info(:
|
31
|
+
h = $client.nodes.info(info: %w[jvm process])
|
26
32
|
node = h["nodes"].values.first
|
33
|
+
|
27
34
|
assert node.key?("jvm"), "expected jvm info to be present"
|
28
35
|
assert node.key?("process"), "expected process info to be present"
|
29
|
-
|
36
|
+
refute node.key?("network"), "expected network info to be absent"
|
30
37
|
end
|
31
38
|
|
32
39
|
it "filters node stats" do
|
33
|
-
h = $client.nodes.stats(:
|
40
|
+
h = $client.nodes.stats(stats: "http")
|
34
41
|
node = h["nodes"].values.first
|
42
|
+
|
35
43
|
assert node.key?("http"), "expected http stats to be present"
|
36
|
-
|
44
|
+
refute node.key?("indices"), "expected indices stats to be absent"
|
37
45
|
end
|
38
46
|
|
39
47
|
it "gets the hot threads for the node(s)" do
|
40
|
-
str = $client.nodes.hot_threads :
|
48
|
+
str = $client.nodes.hot_threads read_timeout: 2
|
49
|
+
|
41
50
|
assert_instance_of String, str
|
42
|
-
|
43
|
-
|
51
|
+
refute_nil str, "expected response to not be nil"
|
52
|
+
refute_empty str, "expected response to not be empty"
|
44
53
|
end
|
45
54
|
|
46
55
|
it "can be scoped to a single node" do
|
47
56
|
h = $client.nodes("node-with-no-name").info
|
57
|
+
|
48
58
|
assert_empty h["nodes"]
|
49
59
|
end
|
50
60
|
|
51
61
|
it "can be scoped to multiple nodes" do
|
52
62
|
h = $client.nodes(%w[node1 node2 node3]).info
|
63
|
+
|
53
64
|
assert_empty h["nodes"]
|
54
65
|
end
|
55
66
|
|
@@ -1,8 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative "../test_helper"
|
2
4
|
|
3
|
-
describe
|
5
|
+
describe ElastomerClient::Client::Percolator do
|
4
6
|
|
5
7
|
before do
|
8
|
+
if $client.version_support.es_version_8_plus?
|
9
|
+
skip "Percolate not supported in ES version #{$client.version}"
|
10
|
+
end
|
11
|
+
|
6
12
|
@index = $client.index "elastomer-percolator-test"
|
7
13
|
@index.delete if @index.exists?
|
8
14
|
@docs = @index.docs("docs")
|
@@ -14,13 +20,7 @@ describe Elastomer::Client::Percolator do
|
|
14
20
|
|
15
21
|
describe "when an index exists" do
|
16
22
|
before do
|
17
|
-
|
18
|
-
base_mappings =
|
19
|
-
if requires_percolator_mapping?
|
20
|
-
{ :mappings => { :percolator => { :properties => { :query => { :type => "percolator" } } } } }
|
21
|
-
else
|
22
|
-
nil
|
23
|
-
end
|
23
|
+
base_mappings = { mappings: { percolator: { properties: { query: { type: "percolator" } } } } }
|
24
24
|
|
25
25
|
@index.create(base_mappings)
|
26
26
|
wait_for_index(@index.name)
|
@@ -28,29 +28,34 @@ describe Elastomer::Client::Percolator do
|
|
28
28
|
|
29
29
|
it "creates a query" do
|
30
30
|
percolator = @index.percolator "1"
|
31
|
-
response = percolator.create :
|
31
|
+
response = percolator.create query: { match_all: { } }
|
32
|
+
|
32
33
|
assert response["created"], "Couldn't create the percolator query"
|
33
34
|
end
|
34
35
|
|
35
36
|
it "gets a query" do
|
36
37
|
percolator = @index.percolator "1"
|
37
|
-
percolator.create :
|
38
|
+
percolator.create query: { match_all: { } }
|
38
39
|
response = percolator.get
|
40
|
+
|
39
41
|
assert response["found"], "Couldn't find the percolator query"
|
40
42
|
end
|
41
43
|
|
42
44
|
it "deletes a query" do
|
43
45
|
percolator = @index.percolator "1"
|
44
|
-
percolator.create :
|
46
|
+
percolator.create query: { match_all: { } }
|
45
47
|
response = percolator.delete
|
48
|
+
|
46
49
|
assert response["found"], "Couldn't find the percolator query"
|
47
50
|
end
|
48
51
|
|
49
52
|
it "checks for the existence of a query" do
|
50
53
|
percolator = @index.percolator "1"
|
51
|
-
|
52
|
-
percolator
|
53
|
-
|
54
|
+
|
55
|
+
refute_predicate percolator, :exists?, "Percolator query exists"
|
56
|
+
percolator.create query: { match_all: { } }
|
57
|
+
|
58
|
+
assert_predicate percolator, :exists?, "Percolator query does not exist"
|
54
59
|
end
|
55
60
|
|
56
61
|
it "cannot delete all percolators by providing a nil id" do
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../test_helper"
|
4
|
+
|
5
|
+
describe ElastomerClient::Client::Reindex do
|
6
|
+
before do
|
7
|
+
@source_index = $client.index("source_index")
|
8
|
+
@dest_index = $client.index("dest_index")
|
9
|
+
@non_existent_index = $client.index("non_existent_index")
|
10
|
+
if @source_index.exists?
|
11
|
+
@source_index.delete
|
12
|
+
end
|
13
|
+
if @dest_index.exists?
|
14
|
+
@dest_index.delete
|
15
|
+
end
|
16
|
+
if @non_existent_index.exists?
|
17
|
+
@non_existent_index.delete
|
18
|
+
end
|
19
|
+
@source_index.create(default_index_settings)
|
20
|
+
@dest_index.create(default_index_settings)
|
21
|
+
wait_for_index(@source_index.name, "green")
|
22
|
+
wait_for_index(@dest_index.name, "green")
|
23
|
+
|
24
|
+
# Index a document in the source index
|
25
|
+
@source_index.docs.index(document_wrapper("book", { _id: 1, title: "Book 1" }))
|
26
|
+
@source_index.refresh
|
27
|
+
end
|
28
|
+
|
29
|
+
after do
|
30
|
+
@source_index.delete if @source_index.exists?
|
31
|
+
@dest_index.delete if @dest_index.exists?
|
32
|
+
@non_existent_index.delete if @non_existent_index.exists?
|
33
|
+
end
|
34
|
+
|
35
|
+
it "reindexes documents from one index to another" do
|
36
|
+
reindex = $client.reindex
|
37
|
+
body = {
|
38
|
+
source: { index: @source_index.name },
|
39
|
+
dest: { index: @dest_index.name }
|
40
|
+
}
|
41
|
+
reindex.reindex(body)
|
42
|
+
|
43
|
+
# Refresh the destination index to make sure the document is searchable
|
44
|
+
@dest_index.refresh
|
45
|
+
|
46
|
+
# Verify that the document has been reindexed
|
47
|
+
doc = @dest_index.docs.get(id: 1, type: "book")
|
48
|
+
|
49
|
+
assert_equal "Book 1", doc["_source"]["title"]
|
50
|
+
end
|
51
|
+
|
52
|
+
it "successfully rethrottles a reindex task" do
|
53
|
+
reindex = $client.reindex
|
54
|
+
body = {
|
55
|
+
source: { index: @source_index.name },
|
56
|
+
dest: { index: @dest_index.name }
|
57
|
+
}
|
58
|
+
response = reindex.reindex(body, requests_per_second: 0.01, wait_for_completion: false)
|
59
|
+
task_id = response["task"]
|
60
|
+
|
61
|
+
reindex.rethrottle(task_id, requests_per_second: 1)
|
62
|
+
|
63
|
+
tasks = $client.tasks
|
64
|
+
node_id = task_id.split(":").first
|
65
|
+
task_id = task_id.split(":").last.to_i
|
66
|
+
|
67
|
+
# wait for the task to complete
|
68
|
+
tasks.wait_by_id(node_id, task_id, "30s")
|
69
|
+
|
70
|
+
# Verify that the document has been reindexed
|
71
|
+
doc = @dest_index.docs.get(id: 1, type: "book")
|
72
|
+
|
73
|
+
assert_equal "Book 1", doc["_source"]["title"]
|
74
|
+
end
|
75
|
+
|
76
|
+
it "creates a new index when the destination index does not exist" do
|
77
|
+
reindex = $client.reindex
|
78
|
+
body = {
|
79
|
+
source: { index: @source_index.name },
|
80
|
+
dest: { index: "non_existent_index" }
|
81
|
+
}
|
82
|
+
reindex.reindex(body)
|
83
|
+
new_index = $client.index("non_existent_index")
|
84
|
+
|
85
|
+
assert_predicate(new_index, :exists?)
|
86
|
+
end
|
87
|
+
|
88
|
+
it "fails when the source index does not exist" do
|
89
|
+
reindex = $client.reindex
|
90
|
+
body = {
|
91
|
+
source: { index: "non_existent_index" },
|
92
|
+
dest: { index: @dest_index.name }
|
93
|
+
}
|
94
|
+
|
95
|
+
exception = assert_raises(ElastomerClient::Client::RequestError) do
|
96
|
+
reindex.reindex(body)
|
97
|
+
end
|
98
|
+
assert_equal(404, exception.status)
|
99
|
+
end
|
100
|
+
end
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative "../test_helper"
|
2
4
|
|
3
|
-
describe
|
5
|
+
describe ElastomerClient::Client::Repository do
|
4
6
|
before do
|
5
7
|
if !run_snapshot_tests?
|
6
8
|
skip "To enable snapshot tests, add a path.repo setting to your elasticsearch.yml file."
|
@@ -11,28 +13,30 @@ describe Elastomer::Client::Repository do
|
|
11
13
|
end
|
12
14
|
|
13
15
|
it "determines if a repo exists" do
|
14
|
-
|
15
|
-
|
16
|
+
refute_predicate @repo, :exists?
|
17
|
+
refute_predicate @repo, :exist?
|
16
18
|
with_tmp_repo(@name) do
|
17
|
-
|
19
|
+
assert_predicate @repo, :exists?
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
21
23
|
it "creates repos" do
|
22
24
|
response = create_repo(@name)
|
23
|
-
|
25
|
+
|
26
|
+
assert response["acknowledged"]
|
24
27
|
delete_repo(@name)
|
25
28
|
end
|
26
29
|
|
27
30
|
it "cannot create a repo without a name" do
|
28
|
-
lambda {
|
31
|
+
_(lambda {
|
29
32
|
create_repo(nil)
|
30
|
-
}.must_raise ArgumentError
|
33
|
+
}).must_raise ArgumentError
|
31
34
|
end
|
32
35
|
|
33
36
|
it "gets repos" do
|
34
37
|
with_tmp_repo do |repo|
|
35
38
|
response = repo.get
|
39
|
+
|
36
40
|
refute_nil response[repo.name]
|
37
41
|
end
|
38
42
|
end
|
@@ -40,6 +44,7 @@ describe Elastomer::Client::Repository do
|
|
40
44
|
it "gets all repos" do
|
41
45
|
with_tmp_repo do |repo|
|
42
46
|
response = $client.repository.get
|
47
|
+
|
43
48
|
refute_nil response[repo.name]
|
44
49
|
end
|
45
50
|
end
|
@@ -47,59 +52,66 @@ describe Elastomer::Client::Repository do
|
|
47
52
|
it "gets repo status" do
|
48
53
|
with_tmp_repo do |repo|
|
49
54
|
response = repo.status
|
50
|
-
|
55
|
+
|
56
|
+
assert_empty response["snapshots"]
|
51
57
|
end
|
52
58
|
end
|
53
59
|
|
54
60
|
it "gets status of all repos" do
|
55
61
|
response = $client.repository.status
|
56
|
-
|
62
|
+
|
63
|
+
assert_empty response["snapshots"]
|
57
64
|
end
|
58
65
|
|
59
66
|
it "updates repos" do
|
60
67
|
with_tmp_repo do |repo|
|
61
68
|
settings = repo.get[repo.name]["settings"]
|
62
|
-
response = repo.update(:
|
63
|
-
|
69
|
+
response = repo.update(type: "fs", settings: settings.merge("compress" => true))
|
70
|
+
|
71
|
+
assert response["acknowledged"]
|
64
72
|
assert_equal "true", repo.get[repo.name]["settings"]["compress"]
|
65
73
|
end
|
66
74
|
end
|
67
75
|
|
68
76
|
it "cannot update a repo without a name" do
|
69
77
|
with_tmp_repo do |repo|
|
70
|
-
lambda {
|
78
|
+
_(lambda {
|
71
79
|
settings = repo.get[repo.name]["settings"]
|
72
|
-
$client.repository.update(:
|
73
|
-
}.must_raise ArgumentError
|
80
|
+
$client.repository.update(type: "fs", settings: settings.merge("compress" => true))
|
81
|
+
}).must_raise ArgumentError
|
74
82
|
end
|
75
83
|
end
|
76
84
|
|
77
85
|
it "deletes repos" do
|
78
86
|
with_tmp_repo do |repo|
|
79
87
|
response = repo.delete
|
80
|
-
|
81
|
-
|
88
|
+
|
89
|
+
assert response["acknowledged"]
|
90
|
+
refute_predicate repo, :exists?
|
82
91
|
end
|
83
92
|
end
|
84
93
|
|
85
94
|
it "cannot delete a repo without a name" do
|
86
|
-
lambda {
|
95
|
+
_(lambda {
|
87
96
|
$client.repository.delete
|
88
|
-
}.must_raise ArgumentError
|
97
|
+
}).must_raise ArgumentError
|
89
98
|
end
|
90
99
|
|
91
100
|
it "gets snapshots" do
|
92
101
|
with_tmp_repo do |repo|
|
93
102
|
response = repo.snapshots.get
|
94
|
-
|
103
|
+
|
104
|
+
assert_empty response["snapshots"]
|
95
105
|
|
96
106
|
create_snapshot(repo, "test-snapshot")
|
97
107
|
response = repo.snapshot.get
|
108
|
+
|
98
109
|
assert_equal ["test-snapshot"], response["snapshots"].collect { |info| info["snapshot"] }
|
99
110
|
|
100
111
|
create_snapshot(repo, "test-snapshot2")
|
101
112
|
response = repo.snapshots.get
|
102
113
|
snapshot_names = response["snapshots"].collect { |info| info["snapshot"] }
|
114
|
+
|
103
115
|
assert_includes snapshot_names, "test-snapshot"
|
104
116
|
assert_includes snapshot_names, "test-snapshot2"
|
105
117
|
end
|
@@ -1,15 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative "../../test_helper"
|
2
4
|
|
3
|
-
describe
|
5
|
+
describe ElastomerClient::Client::RestApiSpec::ApiSpec do
|
4
6
|
before do
|
5
|
-
@api_spec =
|
7
|
+
@api_spec = ElastomerClient::Client::RestApiSpec.api_spec("5.6.4")
|
6
8
|
end
|
7
9
|
|
8
10
|
it "selects valid path parts" do
|
9
|
-
parts = {index
|
11
|
+
parts = {:index => "test", "type" => "doc", :foo => "bar"}
|
10
12
|
result = @api_spec.select_parts(api: "search", from: parts)
|
11
13
|
|
12
|
-
assert_equal({index
|
14
|
+
assert_equal({:index => "test", "type" => "doc"}, result)
|
13
15
|
end
|
14
16
|
|
15
17
|
it "identifies valid path parts" do
|
@@ -19,10 +21,10 @@ describe Elastomer::Client::RestApiSpec::ApiSpec do
|
|
19
21
|
end
|
20
22
|
|
21
23
|
it "selects valid request params" do
|
22
|
-
params = {explain
|
24
|
+
params = {:explain => true, "preference" => "local", :nope => "invalid"}
|
23
25
|
result = @api_spec.select_params(api: "search", from: params)
|
24
26
|
|
25
|
-
assert_equal({explain
|
27
|
+
assert_equal({:explain => true, "preference" => "local"}, result)
|
26
28
|
end
|
27
29
|
|
28
30
|
it "identifies valid request params" do
|
@@ -33,10 +35,10 @@ describe Elastomer::Client::RestApiSpec::ApiSpec do
|
|
33
35
|
end
|
34
36
|
|
35
37
|
it "selects common request params" do
|
36
|
-
params = {pretty
|
38
|
+
params = {:pretty => true, "human" => true, :nope => "invalid"}
|
37
39
|
result = @api_spec.select_common_params(from: params)
|
38
40
|
|
39
|
-
assert_equal({pretty
|
41
|
+
assert_equal({:pretty => true, "human" => true}, result)
|
40
42
|
end
|
41
43
|
|
42
44
|
it "identifies common request params" do
|
@@ -47,9 +49,9 @@ describe Elastomer::Client::RestApiSpec::ApiSpec do
|
|
47
49
|
end
|
48
50
|
|
49
51
|
it "validates request params" do
|
50
|
-
|
51
|
-
|
52
|
-
@api_spec.validate_params!(api: "search", params:
|
52
|
+
params = {q: "*:*", pretty: true, "nope": false}
|
53
|
+
assert_raises(ElastomerClient::Client::IllegalArgument, "'nope' is not a valid parameter for the 'search' API") {
|
54
|
+
@api_spec.validate_params!(api: "search", params:)
|
53
55
|
}
|
54
56
|
end
|
55
57
|
end
|
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative "../../test_helper"
|
2
4
|
|
3
|
-
describe
|
5
|
+
describe ElastomerClient::Client::RestApiSpec::RestApi do
|
4
6
|
before do
|
5
|
-
@rest_api =
|
7
|
+
@rest_api = ElastomerClient::Client::RestApiSpec::RestApi.new \
|
6
8
|
documentation: "https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cluster-state.html",
|
7
9
|
methods: ["GET"],
|
8
10
|
body: nil,
|
@@ -26,9 +28,9 @@ describe Elastomer::Client::RestApiSpec::RestApi do
|
|
26
28
|
|
27
29
|
it "selects valid path parts" do
|
28
30
|
hash = {
|
29
|
-
index
|
31
|
+
:index => "test",
|
30
32
|
"metric" => "os",
|
31
|
-
nope
|
33
|
+
:nope => "not selected"
|
32
34
|
}
|
33
35
|
selected = @rest_api.select_parts(from: hash)
|
34
36
|
|
@@ -45,10 +47,10 @@ describe Elastomer::Client::RestApiSpec::RestApi do
|
|
45
47
|
|
46
48
|
it "selects valid request params" do
|
47
49
|
hash = {
|
48
|
-
local
|
50
|
+
:local => true,
|
49
51
|
"flat_settings" => true,
|
50
|
-
expand_wildcards
|
51
|
-
nope
|
52
|
+
:expand_wildcards => "all",
|
53
|
+
:nope => "not selected"
|
52
54
|
}
|
53
55
|
selected = @rest_api.select_params(from: hash)
|
54
56
|
|
@@ -1,32 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative "../test_helper"
|
2
4
|
|
3
|
-
describe
|
5
|
+
describe ElastomerClient::Client::Scroller do
|
4
6
|
|
5
7
|
before do
|
6
8
|
@name = "elastomer-scroller-test"
|
7
9
|
@index = $client.index(@name)
|
10
|
+
@type = $client.version_support.es_version_8_plus? ? "_doc" : "book"
|
8
11
|
|
9
12
|
unless @index.exists?
|
10
13
|
@index.create \
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:
|
14
|
-
|
15
|
-
:
|
16
|
-
|
17
|
-
|
18
|
-
:sorter => { :type => "integer" }
|
19
|
-
}
|
20
|
-
},
|
21
|
-
:book => {
|
22
|
-
:_source => { :enabled => true }, :_all => { :enabled => false },
|
23
|
-
:properties => {
|
24
|
-
:title => $client.version_support.text(analyzer: "standard"),
|
25
|
-
:author => $client.version_support.keyword,
|
26
|
-
:sorter => { :type => "integer" }
|
27
|
-
}
|
14
|
+
settings: { "index.number_of_shards" => 1, "index.number_of_replicas" => 0 },
|
15
|
+
mappings: mappings_wrapper("book", {
|
16
|
+
_source: { enabled: true },
|
17
|
+
properties: {
|
18
|
+
title: { type: "text", analyzer: "standard" },
|
19
|
+
author: { type: "keyword" },
|
20
|
+
sorter: { type: "integer" }
|
28
21
|
}
|
29
|
-
}
|
22
|
+
}, true)
|
30
23
|
|
31
24
|
wait_for_index(@name)
|
32
25
|
populate!
|
@@ -38,66 +31,53 @@ describe Elastomer::Client::Scroller do
|
|
38
31
|
end
|
39
32
|
|
40
33
|
it "scans over all documents in an index" do
|
41
|
-
scan = @index.scan '{"query":{"match_all":{}}}', :
|
42
|
-
|
43
|
-
counts = {"tweet" => 0, "book" => 0}
|
44
|
-
scan.each_document { |h| counts[h["_type"]] += 1 }
|
45
|
-
|
46
|
-
assert_equal 50, counts["tweet"]
|
47
|
-
assert_equal 25, counts["book"]
|
48
|
-
end
|
49
|
-
|
50
|
-
it "restricts the scan to a single document type" do
|
51
|
-
scan = @index.scan '{"query":{"match_all":{}}}', :type => "book"
|
34
|
+
scan = @index.scan '{"query":{"match_all":{}}}', size: 10
|
52
35
|
|
53
|
-
|
54
|
-
scan.each_document { |h|
|
36
|
+
count = 0
|
37
|
+
scan.each_document { |h| count += 1 }
|
55
38
|
|
56
|
-
assert_equal
|
57
|
-
assert_equal 25, counts["book"]
|
39
|
+
assert_equal 25, count
|
58
40
|
end
|
59
41
|
|
60
42
|
it "limits results by query" do
|
61
|
-
scan = @index.scan :
|
62
|
-
{:
|
63
|
-
{:match => {:title => "17"}}
|
43
|
+
scan = @index.scan query: { bool: { should: [
|
44
|
+
{match: {title: "17"}}
|
64
45
|
]}}
|
65
46
|
|
66
|
-
|
67
|
-
scan.each_document { |h|
|
47
|
+
count = 0
|
48
|
+
scan.each_document { |h| count += 1 }
|
68
49
|
|
69
|
-
assert_equal
|
70
|
-
assert_equal 1, counts["book"]
|
50
|
+
assert_equal 1, count
|
71
51
|
end
|
72
52
|
|
73
53
|
it "scrolls and sorts over all documents" do
|
74
54
|
scroll = @index.scroll({
|
75
|
-
:
|
76
|
-
:
|
77
|
-
}, :type
|
55
|
+
query: {match_all: {}},
|
56
|
+
sort: {sorter: {order: :asc}}
|
57
|
+
}, type: @type)
|
58
|
+
|
59
|
+
books = []
|
60
|
+
scroll.each_document { |h| books << h["_id"].to_i }
|
78
61
|
|
79
|
-
|
80
|
-
scroll.each_document { |h| tweets << h["_id"].to_i }
|
62
|
+
expected = (0...25).to_a.reverse
|
81
63
|
|
82
|
-
expected
|
83
|
-
assert_equal expected, tweets
|
64
|
+
assert_equal expected, books
|
84
65
|
end
|
85
66
|
|
86
67
|
it "propagates URL query strings" do
|
87
|
-
scan = @index.scan(nil, { :
|
68
|
+
scan = @index.scan(nil, { q: "title:1 || title:17" })
|
88
69
|
|
89
|
-
|
90
|
-
scan.each_document { |h|
|
70
|
+
count = 0
|
71
|
+
scan.each_document { |h| count += 1 }
|
91
72
|
|
92
|
-
assert_equal
|
93
|
-
assert_equal 1, counts["book"]
|
73
|
+
assert_equal 2, count
|
94
74
|
end
|
95
75
|
|
96
76
|
it "clears one or more scroll IDs" do
|
97
77
|
h = $client.start_scroll \
|
98
78
|
body: {query: {match_all: {}}},
|
99
79
|
index: @index.name,
|
100
|
-
type:
|
80
|
+
type: @type,
|
101
81
|
scroll: "1m",
|
102
82
|
size: 10
|
103
83
|
|
@@ -105,32 +85,26 @@ describe Elastomer::Client::Scroller do
|
|
105
85
|
|
106
86
|
response = $client.clear_scroll(h["_scroll_id"])
|
107
87
|
|
108
|
-
|
109
|
-
|
110
|
-
assert_equal 1, response["num_freed"]
|
111
|
-
else
|
112
|
-
assert_empty response
|
113
|
-
end
|
88
|
+
assert response["succeeded"]
|
89
|
+
assert_equal 1, response["num_freed"]
|
114
90
|
end
|
115
91
|
|
116
92
|
it "raises an exception on existing sort in query" do
|
117
|
-
assert_raises(ArgumentError) { @index.scan :
|
93
|
+
assert_raises(ArgumentError) { @index.scan sort: [:_doc] , query: {} }
|
118
94
|
end
|
119
95
|
|
120
96
|
def populate!
|
121
|
-
h = @index.bulk do |b|
|
122
|
-
50.times { |num|
|
123
|
-
b.index %Q({"author":"pea53","message":"this is tweet number #{num}","sorter":#{50-num}}), :_id => num, :_type => "tweet"
|
124
|
-
}
|
125
|
-
end
|
126
|
-
h["items"].each {|item| assert_bulk_index(item) }
|
127
|
-
|
128
97
|
h = @index.bulk do |b|
|
129
98
|
25.times { |num|
|
130
|
-
|
99
|
+
if $client.version_support.es_version_8_plus?
|
100
|
+
b.index %Q({"author":"Pratchett","title":"DiscWorld Book #{num}","sorter":#{25-num}}), _id: num
|
101
|
+
else
|
102
|
+
b.index %Q({"author":"Pratchett","title":"DiscWorld Book #{num}","sorter":#{25-num}}), _id: num, _type: "book"
|
103
|
+
end
|
131
104
|
}
|
132
105
|
end
|
133
|
-
|
106
|
+
|
107
|
+
h["items"].each { |item| assert_bulk_index(item) }
|
134
108
|
|
135
109
|
@index.refresh
|
136
110
|
end
|