elastomer-client 3.2.3 → 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 +73 -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 +5 -3
  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 +166 -141
  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
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  # Usage:
3
5
  #
4
6
  # script/generate-rest-api-spec <elasticsearch-version>
@@ -12,19 +14,22 @@ require "rubygems"
12
14
  require "bundler/setup"
13
15
 
14
16
  $LOAD_PATH.unshift "lib"
15
- require "elastomer/client"
17
+ require "elastomer_client/client"
18
+ require "elastomer_client/version_support"
16
19
 
17
20
  class RestApiSpecGenerator
18
21
  WORKING_DIR = "vendor/elasticsearch"
19
22
 
20
23
  attr_reader :version, :short_version, :class_version
21
24
 
22
- def initialize(version = "5.6")
25
+ def initialize(version = "8.13")
23
26
  @version = version
24
27
 
25
- sliced = @version.split(".").slice(0,2)
28
+ sliced = @version.split(".").slice(0, 2)
26
29
  @short_version = sliced.join(".")
27
30
  @class_version = sliced.join("_")
31
+
32
+ @version_support = ElastomerClient::VersionSupport.new(version)
28
33
  end
29
34
 
30
35
  # Setup the working directory and generate the Ruby API spec for the
@@ -32,7 +37,7 @@ class RestApiSpecGenerator
32
37
  def run
33
38
  setup
34
39
  File.open(ruby_spec_filename, "w") do |fd|
35
- fd.puts ERB.new(DATA.read, 0, "-").result(binding)
40
+ fd.puts ERB.new(DATA.read, trim_mode: "-").result(binding)
36
41
  end
37
42
  ensure
38
43
  reset
@@ -40,18 +45,18 @@ class RestApiSpecGenerator
40
45
 
41
46
  # The name of the Ruby API spec file for this particular Elasticsearch version.
42
47
  def ruby_spec_filename
43
- "lib/elastomer/client/rest_api_spec/api_spec_v#{class_version}.rb"
48
+ "lib/elastomer_client/client/rest_api_spec/api_spec_v#{class_version}.rb"
44
49
  end
45
50
 
46
51
  # Returns true if the elasticserach working directory exists.
47
52
  def working_dir_exists?
48
- File.directory?(WORKING_DIR) && File.exists?(WORKING_DIR)
53
+ File.directory?(WORKING_DIR) && File.exist?(WORKING_DIR)
49
54
  end
50
55
 
51
56
  # Iterate over each of the REST API specs yield the name and the descriptor
52
57
  # hash for that particular API spec.
53
58
  def each_api
54
- Dir.glob("#{WORKING_DIR}/rest-api-spec/src/main/resources/rest-api-spec/api/*.json").each do |filename|
59
+ Dir.glob("#{WORKING_DIR}/rest-api-spec/src/main/resources/rest-api-spec/api/*.json").sort.each do |filename|
55
60
  next if filename =~ /\/_common\.json\Z/
56
61
 
57
62
  hash = MultiJson.load(File.read(filename))
@@ -65,12 +70,61 @@ class RestApiSpecGenerator
65
70
  # value pairs.
66
71
  def each_common
67
72
  filename = "#{WORKING_DIR}/rest-api-spec/src/main/resources/rest-api-spec/api/_common.json"
68
- if File.exists? filename
73
+ if File.exist? filename
69
74
  hash = MultiJson.load(File.read(filename))
70
- hash["params"].each {|k,v| yield(k,v)}
75
+ hash["params"].each { |k, v| yield(k, v) }
76
+ end
77
+ end
78
+
79
+ def generate_documentation(data)
80
+ if @version_support.es_version_8_plus?
81
+ data["documentation"]["url"].to_s
82
+ else
83
+ data["documentation"].to_s
84
+ end
85
+ end
86
+
87
+ def generate_methods(data)
88
+ if @version_support.es_version_8_plus?
89
+ data["url"]["paths"].map { |h| h["methods"] }.flatten.uniq
90
+ else
91
+ Array(data["methods"]).to_s
92
+ end
93
+ end
94
+
95
+ def generate_path(url)
96
+ if @version_support.es_version_8_plus?
97
+ url["paths"].map { |h| h["path"] }.flatten.uniq.first
98
+ else
99
+ url["path"]
71
100
  end
72
101
  end
73
102
 
103
+ def generate_paths(url)
104
+ if @version_support.es_version_8_plus?
105
+ url["paths"].map { |h| h["path"] }.flatten.uniq
106
+ else
107
+ Array(url["paths"]).to_s
108
+ end
109
+ end
110
+
111
+ def generate_parts(url)
112
+ if @version_support.es_version_8_plus?
113
+ url["paths"].map { |h| h["parts"] }.compact.reduce({}, :merge)
114
+ else
115
+ url["parts"]
116
+ end
117
+ end
118
+
119
+ def generate_params(data)
120
+ if @version_support.es_version_8_plus?
121
+ data["params"]
122
+ else
123
+ data["url"]["params"]
124
+ end
125
+ end
126
+
127
+
74
128
  # Perform a sparse checkout of the elasticsearch git repository and then check
75
129
  # out the branch corresponding to the ES version passed to this script.
76
130
  def setup
@@ -82,23 +136,23 @@ class RestApiSpecGenerator
82
136
  git remote add -f origin https://github.com/elastic/elasticsearch.git &&
83
137
  git config core.sparsecheckout true &&
84
138
  echo /rest-api-spec/src/main/resources/rest-api-spec/api/ >> .git/info/sparse-checkout &&
85
- git pull origin master
139
+ git pull origin main
86
140
  SH
87
141
  end
88
142
 
89
143
  system <<-SH
90
144
  cd #{WORKING_DIR} &&
91
- git pull origin master &&
145
+ git pull origin main &&
92
146
  git checkout -q origin/#{short_version}
93
147
  SH
94
148
  end
95
149
 
96
- # Reset the elasticsearch working directory back to the master branch of the
150
+ # Reset the elasticsearch working directory back to the main branch of the
97
151
  # git repository.
98
152
  def reset
99
153
  system <<-SH
100
154
  cd #{WORKING_DIR} &&
101
- git checkout master
155
+ git checkout main
102
156
  SH
103
157
  end
104
158
  end
@@ -110,27 +164,28 @@ __END__
110
164
  # Date: <%= Time.now.strftime("%Y-%m-%d") %>
111
165
  # ES version: <%= version %>
112
166
 
113
- module Elastomer::Client::RestApiSpec
167
+ module ElastomerClient::Client::RestApiSpec
114
168
  class ApiSpecV<%= class_version %> < ApiSpec
115
169
  def initialize
116
170
  @rest_apis = {
117
- <% each_api do |name,data| -%>
171
+ <%- each_api do |name,data| -%>
172
+ <%- url = data["url"] -%>
118
173
  "<%= name %>" => RestApi.new(
119
- documentation: "<%= data["documentation"].to_s %>",
120
- methods: <%= Array(data["methods"]).to_s %>,
174
+ documentation: "<%= generate_documentation(data) %>",
175
+ methods: <%= generate_methods(data) %>,
121
176
  body: <%= data["body"] ? data["body"].to_s : "nil" %>,
122
- <% url = data["url"] -%>
123
177
  url: {
124
- path: "<%= url["path"] %>",
125
- paths: <%= Array(url["paths"]).to_s %>,
126
- <% if (parts = url["parts"]) && !parts.empty? -%>
178
+ path: "<%= generate_path(url) %>",
179
+ paths: <%= generate_paths(url) %>,
180
+ <% if (parts = generate_parts(url)) && !parts.empty? -%>
127
181
  parts: {
128
182
  <% parts.each do |k,v| -%>
129
183
  "<%= k %>" => <%= v.to_s %>,
130
184
  <% end -%>
131
185
  },
132
186
  <% end -%>
133
- <% if (params = url["params"]) && !params.empty? -%>
187
+ <% params = generate_params(data) -%>
188
+ <% if !params.nil? && !params.empty? -%>
134
189
  params: {
135
190
  <% params.each do |k,v| -%>
136
191
  "<%= k %>" => <%= v.to_s %>,
data/test/assertions.rb CHANGED
@@ -1,76 +1,69 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Minitest::Assertions
2
- #COMPATIBILITY
3
- # ES 1.0 replaced the 'ok' attribute with a 'created' attribute
4
- # in index responses. Check for either one so we are compatible
5
- # with 0.90 and 1.0.
4
+ # COMPATIBILITY
5
+ # ES8+ response uses "result" instead of "created"
6
6
  def assert_created(response)
7
- assert response["created"] || response["ok"], "document was not created"
7
+ assert $client.version_support.es_version_8_plus? ? response["result"] == "created" : response["created"], "document was not created"
8
8
  end
9
9
 
10
- #COMPATIBILITY
11
- # ES 1.0 replaced the 'ok' attribute with an 'acknowledged' attribute
12
- # in many responses. Check for either one so we are compatible
13
- # with 0.90 and 1.0.
14
10
  def assert_acknowledged(response)
15
- assert response["acknowledged"] || response["ok"], "document was not acknowledged"
11
+ assert response["acknowledged"], "document was not acknowledged"
16
12
  end
17
13
 
18
- #COMPATIBILITY
19
- # ES 1.0 replaced the 'exists' attribute with a 'found' attribute in the
20
- # get document response. Check for either one so we are compatible
21
- # with 0.90 and 1.0.
22
14
  def assert_found(response)
23
- assert response["found"] || response["exists"], "document was not found"
15
+ assert response["found"], "document was not found"
24
16
  end
25
17
 
26
18
  def refute_found(response)
27
19
  refute response["found"] || response["exists"], "document was unexpectedly found"
28
20
  end
29
21
 
30
- #COMPATIBILITY
31
- # ES 1.0 replaced the 'ok' attribute in the bulk response item with a
32
- # 'status' attribute. Here we check for either one for compatibility
33
- # with 0.90 and 1.0.
34
- def assert_bulk_index(item, message="bulk index did not succeed")
35
- ok = item["index"]["ok"]
22
+ def assert_bulk_index(item, message = "bulk index did not succeed")
36
23
  status = item["index"]["status"]
37
- assert ok == true || status == 201, message
24
+
25
+ assert_equal(201, status, message)
38
26
  end
39
27
 
40
- def assert_bulk_create(item, message="bulk create did not succeed")
41
- ok = item["create"]["ok"]
28
+ def assert_bulk_create(item, message = "bulk create did not succeed")
42
29
  status = item["create"]["status"]
43
- assert ok == true || status == 201, message
30
+
31
+ assert_equal(201, status, message)
44
32
  end
45
33
 
46
- def assert_bulk_delete(item, message="bulk delete did not succeed")
47
- ok = item["delete"]["ok"]
34
+ def assert_bulk_delete(item, message = "bulk delete did not succeed")
48
35
  status = item["delete"]["status"]
49
- assert ok == true || status == 200, message
36
+
37
+ assert_equal(200, status, message)
50
38
  end
51
39
 
52
- #COMPATIBILITY
53
- # ES 1.0 nests mappings in a "mappings" element under the index name, e.g.
54
- # mapping["test-index"]["mappings"]["doco"]
55
- # ES 0.90 doesn't have the "mappings" element:
56
- # mapping["test-index"]["doco"]
57
- def assert_mapping_exists(response, type, message="mapping expected to exist, but doesn't")
40
+ # COMPATIBILITY
41
+ # ES8+ no longer supports types
42
+ def assert_mapping_exists(response, type, message = "mapping expected to exist, but doesn't")
58
43
  mapping =
59
- if response.has_key?("mappings")
60
- response["mappings"][type]
44
+ if $client.version_support.es_version_8_plus?
45
+ response["mappings"]
61
46
  else
62
- response[type]
47
+ response["mappings"][type]
63
48
  end
49
+
64
50
  refute_nil mapping, message
65
51
  end
66
52
 
67
- def assert_property_exists(response, type, property, message="property expected to exist, but doesn't")
53
+ # COMPATIBILITY
54
+ # ES8+ no longer supports types
55
+ def assert_property_exists(response, type, property, message = "property expected to exist, but doesn't")
68
56
  mapping =
69
57
  if response.has_key?("mappings")
70
- response["mappings"][type]
58
+ if $client.version_support.es_version_8_plus?
59
+ response["mappings"]
60
+ else
61
+ response["mappings"][type]
62
+ end
71
63
  else
72
64
  response[type]
73
65
  end
66
+
74
67
  assert mapping["properties"].has_key?(property), message
75
68
  end
76
69
  end