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,55 +1,66 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "../test_helper"
2
4
 
3
- describe Elastomer::Client::Nodes do
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(:info => "os")
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
- assert !node.key?("jvm"), "expected jvm info to be absent"
29
+ refute node.key?("jvm"), "expected jvm info to be absent"
24
30
 
25
- h = $client.nodes.info(:info => %w[jvm process])
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
- assert !node.key?("network"), "expected network info to be absent"
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(:stats => "http")
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
- assert !node.key?("indices"), "expected indices stats to be absent"
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 :read_timeout => 2
48
+ str = $client.nodes.hot_threads read_timeout: 2
49
+
41
50
  assert_instance_of String, str
42
- assert !str.nil?, "expected response to not be nil"
43
- assert !str.empty?, "expected response to not be empty"
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 Elastomer::Client::Percolator do
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
- # COMPATIBILITY
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 :query => { :match_all => { } }
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 :query => { :match_all => { } }
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 :query => { :match_all => { } }
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
- refute percolator.exists?, "Percolator query exists"
52
- percolator.create :query => { :match_all => { } }
53
- assert percolator.exists?, "Percolator query does not exist"
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,76 @@
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 "creates a new index when the destination index does not exist" do
53
+ reindex = $client.reindex
54
+ body = {
55
+ source: { index: @source_index.name },
56
+ dest: { index: "non_existent_index" }
57
+ }
58
+ reindex.reindex(body)
59
+ new_index = $client.index("non_existent_index")
60
+
61
+ assert_predicate(new_index, :exists?)
62
+ end
63
+
64
+ it "fails when the source index does not exist" do
65
+ reindex = $client.reindex
66
+ body = {
67
+ source: { index: "non_existent_index" },
68
+ dest: { index: @dest_index.name }
69
+ }
70
+
71
+ exception = assert_raises(ElastomerClient::Client::RequestError) do
72
+ response = reindex.reindex(body)
73
+ end
74
+ assert_equal(404, exception.status)
75
+ end
76
+ end
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "../test_helper"
2
4
 
3
- describe Elastomer::Client::Repository do
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
- assert_equal false, @repo.exists?
15
- assert_equal false, @repo.exist?
16
+ refute_predicate @repo, :exists?
17
+ refute_predicate @repo, :exist?
16
18
  with_tmp_repo(@name) do
17
- assert_equal true, @repo.exists?
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
- assert_equal true, response["acknowledged"]
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
- assert_equal [], response["snapshots"]
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
- assert_equal [], response["snapshots"]
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(:type => "fs", :settings => settings.merge("compress" => true))
63
- assert_equal true, response["acknowledged"]
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(:type => "fs", :settings => settings.merge("compress" => true))
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
- assert_equal true, response["acknowledged"]
81
- assert_equal false, repo.exists?
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
- assert_equal [], response["snapshots"]
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 Elastomer::Client::RestApiSpec::ApiSpec do
5
+ describe ElastomerClient::Client::RestApiSpec::ApiSpec do
4
6
  before do
5
- @api_spec = Elastomer::Client::RestApiSpec.api_spec("5.6.4")
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: "test", "type" => "doc", foo: "bar"}
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: "test", "type" => "doc"}, result)
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: true, "preference" => "local", nope: "invalid"}
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: true, "preference" => "local"}, result)
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: true, "human" => true, nope: "invalid"}
38
+ params = {:pretty => true, "human" => true, :nope => "invalid"}
37
39
  result = @api_spec.select_common_params(from: params)
38
40
 
39
- assert_equal({pretty: true, "human" => true}, result)
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
- assert_raises(Elastomer::Client::IllegalArgument, "'nope' is not a valid parameter for the 'search' API") {
51
- params = {q: "*:*", pretty: true, "nope": false}
52
- @api_spec.validate_params!(api: "search", params: 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 Elastomer::Client::RestApiSpec::RestApi do
5
+ describe ElastomerClient::Client::RestApiSpec::RestApi do
4
6
  before do
5
- @rest_api = Elastomer::Client::RestApiSpec::RestApi.new \
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: "test",
31
+ :index => "test",
30
32
  "metric" => "os",
31
- nope: "not selected"
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: true,
50
+ :local => true,
49
51
  "flat_settings" => true,
50
- expand_wildcards: "all",
51
- nope: "not selected"
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 Elastomer::Client::Scroller do
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
- :settings => { "index.number_of_shards" => 1, "index.number_of_replicas" => 0 },
12
- :mappings => {
13
- :tweet => {
14
- :_source => { :enabled => true }, :_all => { :enabled => false },
15
- :properties => {
16
- :message => $client.version_support.text(analyzer: "standard"),
17
- :author => $client.version_support.keyword,
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":{}}}', :size => 10
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
- counts = {"tweet" => 0, "book" => 0}
54
- scan.each_document { |h| counts[h["_type"]] += 1 }
36
+ count = 0
37
+ scan.each_document { |h| count += 1 }
55
38
 
56
- assert_equal 0, counts["tweet"]
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 :query => { :bool => { :should => [
62
- {:match => {:author => "pea53"}},
63
- {:match => {:title => "17"}}
43
+ scan = @index.scan query: { bool: { should: [
44
+ {match: {title: "17"}}
64
45
  ]}}
65
46
 
66
- counts = {"tweet" => 0, "book" => 0}
67
- scan.each_document { |h| counts[h["_type"]] += 1 }
47
+ count = 0
48
+ scan.each_document { |h| count += 1 }
68
49
 
69
- assert_equal 50, counts["tweet"]
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
- :query => {:match_all => {}},
76
- :sort => {:sorter => {:order => :asc}}
77
- }, :type => "tweet")
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
- tweets = []
80
- scroll.each_document { |h| tweets << h["_id"].to_i }
62
+ expected = (0...25).to_a.reverse
81
63
 
82
- expected = (0...50).to_a.reverse
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, { :q => "author:pea53 || title:17" })
68
+ scan = @index.scan(nil, { q: "title:1 || title:17" })
88
69
 
89
- counts = {"tweet" => 0, "book" => 0}
90
- scan.each_document { |h| counts[h["_type"]] += 1 }
70
+ count = 0
71
+ scan.each_document { |h| count += 1 }
91
72
 
92
- assert_equal 50, counts["tweet"]
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: "tweet",
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
- if returns_cleared_scroll_id_info?
109
- assert response["succeeded"]
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 :sort => [:_doc] , :query => {} }
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
- b.index %Q({"author":"Pratchett","title":"DiscWorld Book #{num}","sorter":#{25-num}}), :_id => num, :_type => "book"
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
- h["items"].each {|item| assert_bulk_index(item) }
106
+
107
+ h["items"].each { |item| assert_bulk_index(item) }
134
108
 
135
109
  @index.refresh
136
110
  end