elasticsearch-api 7.11.2 → 7.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -4
  3. data/README.md +22 -45
  4. data/Rakefile +35 -65
  5. data/elasticsearch-api.gemspec +14 -8
  6. data/lib/elasticsearch/api/actions/bulk.rb +2 -2
  7. data/lib/elasticsearch/api/actions/cat/aliases.rb +1 -1
  8. data/lib/elasticsearch/api/actions/cat/allocation.rb +1 -1
  9. data/lib/elasticsearch/api/actions/cat/count.rb +1 -1
  10. data/lib/elasticsearch/api/actions/cat/fielddata.rb +1 -1
  11. data/lib/elasticsearch/api/actions/cat/health.rb +1 -1
  12. data/lib/elasticsearch/api/actions/cat/help.rb +1 -1
  13. data/lib/elasticsearch/api/actions/cat/indices.rb +1 -1
  14. data/lib/elasticsearch/api/actions/cat/master.rb +1 -1
  15. data/lib/elasticsearch/api/actions/cat/nodeattrs.rb +1 -1
  16. data/lib/elasticsearch/api/actions/cat/nodes.rb +4 -2
  17. data/lib/elasticsearch/api/actions/cat/pending_tasks.rb +1 -1
  18. data/lib/elasticsearch/api/actions/cat/plugins.rb +3 -1
  19. data/lib/elasticsearch/api/actions/cat/recovery.rb +1 -1
  20. data/lib/elasticsearch/api/actions/cat/repositories.rb +1 -1
  21. data/lib/elasticsearch/api/actions/cat/segments.rb +1 -1
  22. data/lib/elasticsearch/api/actions/cat/shards.rb +1 -1
  23. data/lib/elasticsearch/api/actions/cat/snapshots.rb +1 -1
  24. data/lib/elasticsearch/api/actions/cat/tasks.rb +1 -1
  25. data/lib/elasticsearch/api/actions/cat/templates.rb +1 -1
  26. data/lib/elasticsearch/api/actions/cat/thread_pool.rb +1 -1
  27. data/lib/elasticsearch/api/actions/clear_scroll.rb +1 -1
  28. data/lib/elasticsearch/api/actions/{abort_benchmark.rb → close_point_in_time.rb} +13 -12
  29. data/lib/elasticsearch/api/actions/cluster/allocation_explain.rb +3 -3
  30. data/lib/elasticsearch/api/actions/cluster/delete_component_template.rb +1 -1
  31. data/lib/elasticsearch/api/actions/cluster/delete_voting_config_exclusions.rb +1 -1
  32. data/lib/elasticsearch/api/actions/cluster/exists_component_template.rb +2 -1
  33. data/lib/elasticsearch/api/actions/cluster/get_component_template.rb +1 -1
  34. data/lib/elasticsearch/api/actions/cluster/get_settings.rb +1 -1
  35. data/lib/elasticsearch/api/actions/cluster/health.rb +1 -1
  36. data/lib/elasticsearch/api/actions/cluster/pending_tasks.rb +1 -1
  37. data/lib/elasticsearch/api/actions/cluster/post_voting_config_exclusions.rb +1 -1
  38. data/lib/elasticsearch/api/actions/cluster/put_component_template.rb +1 -1
  39. data/lib/elasticsearch/api/actions/cluster/put_settings.rb +1 -1
  40. data/lib/elasticsearch/api/actions/cluster/remote_info.rb +1 -1
  41. data/lib/elasticsearch/api/actions/cluster/reroute.rb +1 -1
  42. data/lib/elasticsearch/api/actions/cluster/state.rb +1 -1
  43. data/lib/elasticsearch/api/actions/cluster/stats.rb +1 -1
  44. data/lib/elasticsearch/api/actions/count.rb +7 -2
  45. data/lib/elasticsearch/api/actions/create.rb +1 -1
  46. data/lib/elasticsearch/api/actions/dangling_indices/delete_dangling_index.rb +1 -1
  47. data/lib/elasticsearch/api/actions/dangling_indices/import_dangling_index.rb +1 -1
  48. data/lib/elasticsearch/api/actions/dangling_indices/list_dangling_indices.rb +1 -1
  49. data/lib/elasticsearch/api/actions/delete.rb +1 -1
  50. data/lib/elasticsearch/api/actions/delete_by_query.rb +1 -7
  51. data/lib/elasticsearch/api/actions/delete_by_query_rethrottle.rb +1 -1
  52. data/lib/elasticsearch/api/actions/delete_script.rb +1 -1
  53. data/lib/elasticsearch/api/actions/exists.rb +2 -1
  54. data/lib/elasticsearch/api/actions/exists_source.rb +2 -1
  55. data/lib/elasticsearch/api/actions/explain.rb +6 -6
  56. data/lib/elasticsearch/api/actions/{nodes/shutdown.rb → features/get_features.rb} +16 -21
  57. data/lib/elasticsearch/api/actions/features/params_registry.rb +60 -0
  58. data/lib/elasticsearch/api/actions/features/reset_features.rb +47 -0
  59. data/lib/elasticsearch/api/actions/field_caps.rb +6 -6
  60. data/lib/elasticsearch/api/actions/get.rb +1 -1
  61. data/lib/elasticsearch/api/actions/get_script.rb +1 -1
  62. data/lib/elasticsearch/api/actions/get_script_context.rb +1 -5
  63. data/lib/elasticsearch/api/actions/get_script_languages.rb +1 -5
  64. data/lib/elasticsearch/api/actions/get_source.rb +1 -1
  65. data/lib/elasticsearch/api/actions/index.rb +1 -1
  66. data/lib/elasticsearch/api/actions/indices/add_block.rb +1 -1
  67. data/lib/elasticsearch/api/actions/indices/analyze.rb +6 -6
  68. data/lib/elasticsearch/api/actions/indices/clear_cache.rb +1 -1
  69. data/lib/elasticsearch/api/actions/indices/clone.rb +1 -1
  70. data/lib/elasticsearch/api/actions/indices/close.rb +2 -2
  71. data/lib/elasticsearch/api/actions/indices/create.rb +1 -1
  72. data/lib/elasticsearch/api/actions/indices/delete.rb +2 -2
  73. data/lib/elasticsearch/api/actions/indices/delete_alias.rb +1 -1
  74. data/lib/elasticsearch/api/actions/indices/delete_index_template.rb +6 -2
  75. data/lib/elasticsearch/api/actions/indices/delete_template.rb +1 -1
  76. data/lib/elasticsearch/api/actions/indices/disk_usage.rb +68 -0
  77. data/lib/elasticsearch/api/actions/indices/exists.rb +2 -1
  78. data/lib/elasticsearch/api/actions/indices/exists_alias.rb +2 -1
  79. data/lib/elasticsearch/api/actions/indices/exists_index_template.rb +6 -2
  80. data/lib/elasticsearch/api/actions/indices/exists_template.rb +2 -1
  81. data/lib/elasticsearch/api/actions/indices/exists_type.rb +2 -1
  82. data/lib/elasticsearch/api/actions/indices/field_usage_stats.rb +66 -0
  83. data/lib/elasticsearch/api/actions/indices/flush.rb +1 -1
  84. data/lib/elasticsearch/api/actions/indices/flush_synced.rb +1 -1
  85. data/lib/elasticsearch/api/actions/indices/forcemerge.rb +1 -1
  86. data/lib/elasticsearch/api/actions/indices/get.rb +1 -1
  87. data/lib/elasticsearch/api/actions/indices/get_alias.rb +1 -1
  88. data/lib/elasticsearch/api/actions/indices/get_field_mapping.rb +1 -1
  89. data/lib/elasticsearch/api/actions/indices/get_index_template.rb +2 -2
  90. data/lib/elasticsearch/api/actions/indices/get_mapping.rb +1 -1
  91. data/lib/elasticsearch/api/actions/indices/get_settings.rb +1 -1
  92. data/lib/elasticsearch/api/actions/indices/get_template.rb +1 -1
  93. data/lib/elasticsearch/api/actions/indices/get_upgrade.rb +1 -1
  94. data/lib/elasticsearch/api/actions/indices/open.rb +1 -1
  95. data/lib/elasticsearch/api/actions/indices/put_alias.rb +1 -1
  96. data/lib/elasticsearch/api/actions/indices/put_index_template.rb +1 -1
  97. data/lib/elasticsearch/api/actions/indices/put_mapping.rb +1 -1
  98. data/lib/elasticsearch/api/actions/indices/put_settings.rb +1 -1
  99. data/lib/elasticsearch/api/actions/indices/put_template.rb +1 -1
  100. data/lib/elasticsearch/api/actions/indices/recovery.rb +1 -1
  101. data/lib/elasticsearch/api/actions/indices/refresh.rb +1 -1
  102. data/lib/elasticsearch/api/actions/indices/resolve_index.rb +1 -5
  103. data/lib/elasticsearch/api/actions/indices/rollover.rb +1 -1
  104. data/lib/elasticsearch/api/actions/indices/segments.rb +1 -1
  105. data/lib/elasticsearch/api/actions/indices/shard_stores.rb +1 -1
  106. data/lib/elasticsearch/api/actions/indices/shrink.rb +1 -1
  107. data/lib/elasticsearch/api/actions/indices/simulate_index_template.rb +1 -1
  108. data/lib/elasticsearch/api/actions/indices/simulate_template.rb +1 -1
  109. data/lib/elasticsearch/api/actions/indices/split.rb +1 -1
  110. data/lib/elasticsearch/api/actions/indices/stats.rb +1 -1
  111. data/lib/elasticsearch/api/actions/indices/update_aliases.rb +1 -1
  112. data/lib/elasticsearch/api/actions/indices/upgrade.rb +1 -1
  113. data/lib/elasticsearch/api/actions/indices/validate_query.rb +8 -8
  114. data/lib/elasticsearch/api/actions/info.rb +1 -1
  115. data/lib/elasticsearch/api/actions/ingest/delete_pipeline.rb +1 -1
  116. data/lib/elasticsearch/api/actions/ingest/geo_ip_stats.rb +43 -0
  117. data/lib/elasticsearch/api/actions/ingest/get_pipeline.rb +3 -1
  118. data/lib/elasticsearch/api/actions/ingest/processor_grok.rb +1 -1
  119. data/lib/elasticsearch/api/actions/ingest/put_pipeline.rb +3 -1
  120. data/lib/elasticsearch/api/actions/ingest/simulate.rb +1 -1
  121. data/lib/elasticsearch/api/actions/mget.rb +1 -1
  122. data/lib/elasticsearch/api/actions/msearch.rb +3 -3
  123. data/lib/elasticsearch/api/actions/msearch_template.rb +3 -3
  124. data/lib/elasticsearch/api/actions/mtermvectors.rb +8 -8
  125. data/lib/elasticsearch/api/actions/nodes/clear_repositories_metering_archive.rb +56 -0
  126. data/lib/elasticsearch/api/actions/nodes/get_repositories_metering_info.rb +52 -0
  127. data/lib/elasticsearch/api/actions/nodes/hot_threads.rb +4 -2
  128. data/lib/elasticsearch/api/actions/nodes/info.rb +2 -2
  129. data/lib/elasticsearch/api/actions/nodes/reload_secure_settings.rb +1 -1
  130. data/lib/elasticsearch/api/actions/nodes/stats.rb +5 -3
  131. data/lib/elasticsearch/api/actions/nodes/usage.rb +1 -1
  132. data/lib/elasticsearch/api/actions/open_point_in_time.rb +62 -0
  133. data/lib/elasticsearch/api/actions/ping.rb +3 -3
  134. data/lib/elasticsearch/api/actions/put_script.rb +1 -1
  135. data/lib/elasticsearch/api/actions/rank_eval.rb +1 -5
  136. data/lib/elasticsearch/api/actions/reindex.rb +1 -1
  137. data/lib/elasticsearch/api/actions/reindex_rethrottle.rb +1 -1
  138. data/lib/elasticsearch/api/actions/render_search_template.rb +6 -6
  139. data/lib/elasticsearch/api/actions/scripts_painless_execute.rb +2 -2
  140. data/lib/elasticsearch/api/actions/scroll.rb +6 -6
  141. data/lib/elasticsearch/api/actions/search.rb +11 -9
  142. data/lib/elasticsearch/api/actions/search_mvt.rb +85 -0
  143. data/lib/elasticsearch/api/actions/search_shards.rb +1 -1
  144. data/lib/elasticsearch/api/actions/search_template.rb +2 -2
  145. data/lib/elasticsearch/api/actions/shutdown/delete_node.rb +48 -0
  146. data/lib/elasticsearch/api/actions/shutdown/get_node.rb +50 -0
  147. data/lib/elasticsearch/api/actions/shutdown/params_registry.rb +60 -0
  148. data/lib/elasticsearch/api/actions/shutdown/put_node.rb +50 -0
  149. data/lib/elasticsearch/api/actions/snapshot/cleanup_repository.rb +1 -1
  150. data/lib/elasticsearch/api/actions/snapshot/clone.rb +1 -1
  151. data/lib/elasticsearch/api/actions/snapshot/create.rb +1 -1
  152. data/lib/elasticsearch/api/actions/snapshot/create_repository.rb +1 -1
  153. data/lib/elasticsearch/api/actions/snapshot/delete.rb +1 -1
  154. data/lib/elasticsearch/api/actions/snapshot/delete_repository.rb +1 -1
  155. data/lib/elasticsearch/api/actions/snapshot/get.rb +5 -1
  156. data/lib/elasticsearch/api/actions/snapshot/get_repository.rb +1 -1
  157. data/lib/elasticsearch/api/actions/snapshot/repository_analyze.rb +76 -0
  158. data/lib/elasticsearch/api/actions/snapshot/restore.rb +1 -1
  159. data/lib/elasticsearch/api/actions/snapshot/status.rb +1 -1
  160. data/lib/elasticsearch/api/actions/snapshot/verify_repository.rb +1 -1
  161. data/lib/elasticsearch/api/actions/tasks/cancel.rb +1 -1
  162. data/lib/elasticsearch/api/actions/tasks/get.rb +1 -1
  163. data/lib/elasticsearch/api/actions/tasks/list.rb +1 -1
  164. data/lib/elasticsearch/api/actions/termvectors.rb +11 -10
  165. data/lib/elasticsearch/api/actions/update.rb +1 -1
  166. data/lib/elasticsearch/api/actions/update_by_query.rb +1 -7
  167. data/lib/elasticsearch/api/actions/update_by_query_rethrottle.rb +1 -1
  168. data/lib/elasticsearch/api/{actions/remote/info.rb → namespace/features.rb} +12 -13
  169. data/lib/elasticsearch/api/namespace/security.rb +36 -0
  170. data/lib/elasticsearch/api/namespace/shutdown.rb +37 -0
  171. data/lib/elasticsearch/api/utils.rb +7 -3
  172. data/lib/elasticsearch/api/version.rb +1 -1
  173. data/lib/elasticsearch/api.rb +3 -1
  174. data/spec/elasticsearch/api/actions/{benchmark_spec.rb → close_point_in_time_spec.rb} +6 -6
  175. data/spec/elasticsearch/api/actions/count_spec.rb +2 -5
  176. data/spec/elasticsearch/api/actions/{remote/info_spec.rb → features/get_features_spec.rb} +7 -8
  177. data/spec/elasticsearch/api/actions/features/reset_features_spec.rb +34 -0
  178. data/spec/elasticsearch/api/actions/indices/clear_cache_spec.rb +16 -3
  179. data/spec/elasticsearch/api/actions/indices/disk_usage_spec.rb +48 -0
  180. data/spec/elasticsearch/api/actions/indices/field_usage_stats_spec.rb +46 -0
  181. data/spec/elasticsearch/api/actions/ingest/geo_ip_stats_spec.rb +34 -0
  182. data/spec/elasticsearch/api/actions/nodes/clear_repositories_metering_archive_spec.rb +51 -0
  183. data/spec/elasticsearch/api/actions/nodes/get_repositories_metering_info_spec.rb +44 -0
  184. data/spec/elasticsearch/api/actions/{abort_benchmark_spec.rb → open_point_in_time_spec.rb} +5 -5
  185. data/spec/elasticsearch/api/actions/search_mvt_spec.rb +52 -0
  186. data/spec/elasticsearch/api/actions/shutdown/delete_node_spec.rb +44 -0
  187. data/spec/elasticsearch/api/actions/shutdown/get_node_spec.rb +46 -0
  188. data/spec/elasticsearch/api/actions/shutdown/put_node_spec.rb +50 -0
  189. data/spec/elasticsearch/api/actions/snapshot/repository_analize_spec.rb +48 -0
  190. data/spec/elasticsearch/api/rest_api_yaml_spec.rb +24 -5
  191. data/spec/elasticsearch/api/utils_spec.rb +9 -21
  192. data/spec/rest_yaml_tests_helper.rb +76 -62
  193. data/spec/skipped_tests.yml +29 -0
  194. data/spec/spec_helper.rb +9 -2
  195. data/utils/Gemfile +4 -3
  196. data/utils/README.md +6 -1
  197. data/utils/thor/.rubocop.yml +2 -0
  198. data/utils/thor/generate_source.rb +18 -13
  199. data/utils/thor/generator/endpoint_specifics.rb +7 -1
  200. data/utils/thor/generator/files_helper.rb +38 -20
  201. data/utils/thor/templates/_documentation_top.erb +19 -0
  202. data/utils/thor/templates/_method_setup.erb +18 -0
  203. data/utils/thor/templates/_params_registry.erb +19 -0
  204. data/utils/thor/templates/_perform_request.erb +20 -2
  205. data/utils/thor/templates/test.erb +16 -3
  206. data/utils/thor/templates/test_helper.rb +0 -4
  207. metadata +68 -44
  208. data/lib/elasticsearch/api/actions/benchmark.rb +0 -81
  209. data/lib/elasticsearch/api/actions/delete_by_rethrottle.rb +0 -47
  210. data/lib/elasticsearch/api/actions/indices/freeze.rb +0 -56
  211. data/lib/elasticsearch/api/actions/indices/unfreeze.rb +0 -56
  212. data/spec/elasticsearch/api/actions/indices/freeze_spec.rb +0 -85
  213. data/spec/elasticsearch/api/actions/indices/unfreeze_spec.rb +0 -85
  214. data/spec/elasticsearch/api/actions/nodes/shutdown_spec.rb +0 -76
@@ -17,10 +17,13 @@
17
17
 
18
18
  require "#{File.expand_path(File.dirname('..'), '..')}/api-spec-testing/test_file"
19
19
  require "#{File.expand_path(File.dirname('..'), '..')}/api-spec-testing/rspec_matchers"
20
+ require "#{File.expand_path(File.dirname('..'), '..')}/api-spec-testing/wipe_cluster"
20
21
  include Elasticsearch::RestAPIYAMLTests
21
22
 
22
23
  TRANSPORT_OPTIONS = {}
23
- PROJECT_PATH = File.join(File.dirname(__FILE__), '..', '..')
24
+ PROJECT_PATH = File.join(File.dirname(__FILE__), '..')
25
+ STACK_VERSION = ENV['STACK_VERSION']
26
+ require 'elasticsearch/xpack'
24
27
 
25
28
  if (hosts = ELASTICSEARCH_URL)
26
29
  split_hosts = hosts.split(',').map do |host|
@@ -33,85 +36,96 @@ else
33
36
  TEST_HOST, TEST_PORT = 'localhost', '9200'
34
37
  end
35
38
 
36
- if defined?(TEST_HOST) && defined?(TEST_PORT)
37
- URL = "http://#{TEST_HOST}:#{TEST_PORT}"
38
-
39
- ADMIN_CLIENT = Elasticsearch::Client.new(host: URL, transport_options: TRANSPORT_OPTIONS)
39
+ test_suite = ENV['TEST_SUITE'] || 'free'
40
+ password = ENV['ELASTIC_PASSWORD'] || 'changeme'
41
+ user = ENV['ELASTIC_USER'] || 'elastic'
40
42
 
41
- if ENV['QUIET'] == 'true'
42
- DEFAULT_CLIENT = Elasticsearch::Client.new(host: URL, transport_options: TRANSPORT_OPTIONS)
43
+ if defined?(TEST_HOST) && defined?(TEST_PORT)
44
+ URL = "http://#{TEST_HOST}:#{TEST_PORT}".freeze
45
+
46
+ if STACK_VERSION.match?(/^8\./)
47
+ if ENV['TEST_SUITE'] == 'platinum'
48
+ raw_certificate = File.read(File.join(PROJECT_PATH, '../.ci/certs/testnode.crt'))
49
+ certificate = OpenSSL::X509::Certificate.new(raw_certificate)
50
+ raw_key = File.read(File.join(PROJECT_PATH, '../.ci/certs/testnode.key'))
51
+ key = OpenSSL::PKey::RSA.new(raw_key)
52
+ ca_file = File.expand_path(File.join(PROJECT_PATH, '/.ci/certs/ca.crt'))
53
+ host = "https://elastic:#{password}@#{uri.host}:#{uri.port}".freeze
54
+ transport_options = { ssl: { verify: false, client_cert: certificate, client_key: key, ca_file: ca_file } }
55
+ else
56
+ host = "http://elastic:#{password}@#{uri.host}:#{uri.port}".freeze
57
+ transport_options = {}
58
+ end
59
+
60
+ ADMIN_CLIENT = Elasticsearch::Client.new(host: host, transport_options: transport_options)
61
+
62
+ DEFAULT_CLIENT = if ENV['QUIET'] == 'true'
63
+ Elasticsearch::Client.new(host: host, transport_options: transport_options)
64
+ else
65
+ Elasticsearch::Client.new(
66
+ host: host,
67
+ tracer: Logger.new($stdout),
68
+ transport_options: transport_options
69
+ )
70
+ end
71
+
72
+ if ENV['QUIET'] == 'true'
73
+ DEFAULT_CLIENT = Elasticsearch::Client.new(
74
+ host: URL,
75
+ transport_options: TRANSPORT_OPTIONS,
76
+ user: user,
77
+ password: password
78
+ )
79
+ else
80
+ DEFAULT_CLIENT = Elasticsearch::Client.new(
81
+ host: URL,
82
+ transport_options: TRANSPORT_OPTIONS,
83
+ user: user,
84
+ password: password,
85
+ tracer: Logger.new($stdout)
86
+ )
87
+ end
43
88
  else
44
- DEFAULT_CLIENT = Elasticsearch::Client.new(host: URL,
45
- transport_options: TRANSPORT_OPTIONS,
46
- tracer: Logger.new($stdout))
89
+ ADMIN_CLIENT = Elasticsearch::Client.new(host: URL, transport_options: TRANSPORT_OPTIONS)
90
+
91
+ if ENV['QUIET'] == 'true'
92
+ DEFAULT_CLIENT = Elasticsearch::Client.new(host: URL, transport_options: TRANSPORT_OPTIONS)
93
+ else
94
+ DEFAULT_CLIENT = Elasticsearch::Client.new(host: URL,
95
+ transport_options: TRANSPORT_OPTIONS,
96
+ tracer: Logger.new($stdout))
97
+ end
47
98
  end
48
99
  end
49
100
 
50
-
51
- YAML_FILES_DIRECTORY = "#{File.expand_path(File.dirname('..'), '..')}" +
52
- '/tmp/elasticsearch/rest-api-spec/src/main/resources/rest-api-spec/test'
101
+ YAML_FILES_DIRECTORY = "#{PROJECT_PATH}/../tmp/rest-api-spec/#{STACK_VERSION.match?(/^8\./) ? 'compatTest' : 'test'}/free"
53
102
 
54
103
  SINGLE_TEST = if ENV['SINGLE_TEST'] && !ENV['SINGLE_TEST'].empty?
55
104
  test_target = ENV['SINGLE_TEST']
56
- path = File.expand_path(File.dirname('..'), '..')
57
105
 
58
106
  if test_target.match?(/\.yml$/)
59
- ["#{path}/tmp/elasticsearch/rest-api-spec/src/main/resources/rest-api-spec/test/#{test_target}"]
107
+ ["#{PROJECT_PATH}/../tmp/rest-api-spec/test/free/#{test_target}"]
60
108
  else
61
109
  Dir.glob(
62
- ["#{path}/tmp/elasticsearch/rest-api-spec/src/main/resources/rest-api-spec/test/#{test_target}/*.yml"]
110
+ ["#{PROJECT_PATH}/../tmp/rest-api-spec/test/free/#{test_target}/*.yml"]
63
111
  )
64
112
  end
65
113
  end
66
114
 
67
- skipped_tests = []
68
-
69
- # Response from Elasticsearch is just a String, so it's not possible to compare using headers.
70
- skipped_tests << { file: 'cat.aliases/20_headers.yml',
71
- description: 'Simple alias with yaml body through Accept header' }
72
-
73
- # Check version skip logic
74
- skipped_tests << { file: 'create/15_without_id.yml',
75
- description: 'Create without ID' }
76
-
77
- # No error is raised
78
- skipped_tests << { file: 'create/15_without_id_with_types.yml',
79
- description: 'Create without ID' }
80
-
81
- # Error message doesn't match
82
- skipped_tests << { file: 'tasks.get/10_basic.yml',
83
- description: 'get task test' }
84
-
85
- # No error is raised
86
- skipped_tests << { file: 'cat.allocation/10_basic.yml',
87
- description: '*' }
88
-
89
- # Figure out how to match response when there is an error
90
- skipped_tests << { file: 'delete/70_mix_typeless_typeful.yml',
91
- description: '*' }
92
-
93
- # Figure out how to match response when there is an error
94
- skipped_tests << { file: 'cat.templates/10_basic.yml',
95
- description: '*' }
96
-
97
- # Responses are there but not equal (eg.: yellow status)
98
- skipped_tests << { file: 'cluster.health/10_basic.yml',
99
- description: 'cluster health with closed index (pre 7.2.0)' }
100
-
101
- # Regular expression not catching exact match:
102
- skipped_tests << { file: 'cat.indices/10_basic.yml',
103
- description: 'Test cat indices output for closed index (pre 7.2.0)' }
104
-
105
- # TODO
106
- skipped_tests << {
107
- file: 'nodes.info/10_basic.yml',
108
- description: 'node_info role test'
109
- }
110
-
111
- SKIPPED_TESTS = skipped_tests
115
+ # Skipped tests
116
+ file = File.expand_path("#{__dir__}/skipped_tests.yml")
117
+ skipped_tests = YAML.load_file(file)
112
118
 
113
119
  # The directory of rest api YAML files.
114
- REST_API_YAML_FILES = SINGLE_TEST || Dir.glob("#{YAML_FILES_DIRECTORY}/**/*.yml")
120
+ REST_API_YAML_FILES = if ENV['RUN_SKIPPED_TESTS'] # only run the skipped tests if true
121
+ SKIPPED_TESTS = []
122
+ skipped_tests.map { |test| "#{YAML_FILES_DIRECTORY}/#{test[:file]}" }
123
+ else
124
+ # If not, define the skipped tests constant and try the single test or all
125
+ # the tests
126
+ SKIPPED_TESTS = skipped_tests
127
+ SINGLE_TEST || Dir.glob("#{YAML_FILES_DIRECTORY}/**/*.yml")
128
+ end
115
129
 
116
130
  # The features to skip
117
131
  REST_API_YAML_SKIP_FEATURES = ['warnings', 'node_selector'].freeze
@@ -0,0 +1,29 @@
1
+ # Response from Elasticsearch is just a String, so it's not possible to compare using headers.
2
+ -
3
+ :file: 'cat.aliases/20_headers.yml'
4
+ :description: 'Simple alias with yaml body through Accept header'
5
+
6
+ # Check version skip logic
7
+ -
8
+ :file: 'create/15_without_id.yml'
9
+ :description: 'Create without ID'
10
+
11
+ # No error is raised
12
+ -
13
+ :file: 'create/15_without_id_with_types.yml'
14
+ :description: 'Create without ID'
15
+
16
+ # Error message doesn't match
17
+ -
18
+ :file: 'tasks.get/10_basic.yml'
19
+ :description: 'get task test'
20
+
21
+ # Figure out how to match response when there is an error
22
+ -
23
+ :file: 'delete/70_mix_typeless_typeful.yml'
24
+ :description: '*'
25
+
26
+ # Figure out how to match response when there is an error
27
+ -
28
+ :file: 'cat.templates/10_basic.yml'
29
+ :description: '*'
data/spec/spec_helper.rb CHANGED
@@ -14,6 +14,10 @@
14
14
  # KIND, either express or implied. See the License for the
15
15
  # specific language governing permissions and limitations
16
16
  # under the License.
17
+ if ENV['COVERAGE'] && ENV['CI'].nil?
18
+ require 'simplecov'
19
+ SimpleCov.start { add_filter %r{^/test|spec/} }
20
+ end
17
21
 
18
22
  if defined?(JRUBY_VERSION)
19
23
  require 'pry-nav'
@@ -21,6 +25,10 @@ else
21
25
  require 'pry-byebug'
22
26
  end
23
27
  require 'ansi'
28
+ require 'yaml'
29
+ require 'active_support/isolated_execution_state' unless RUBY_VERSION < '2.7.0'
30
+ require 'jbuilder'
31
+ require 'jsonify'
24
32
  require 'elasticsearch'
25
33
  require 'elasticsearch-api'
26
34
  require 'elasticsearch-transport'
@@ -42,7 +50,6 @@ DEFAULT_CLIENT = Elasticsearch::Client.new(host: ELASTICSEARCH_URL,
42
50
 
43
51
  module HelperModule
44
52
  def self.included(context)
45
-
46
53
  context.let(:client_double) do
47
54
  Class.new { include Elasticsearch::API }.new.tap do |client|
48
55
  expect(client).to receive(:perform_request).with(*expected_args).and_return(response_double)
@@ -64,7 +71,7 @@ end
64
71
  RSpec.configure do |config|
65
72
  config.include(HelperModule)
66
73
  config.formatter = 'documentation'
67
- config.color = true
74
+ config.color_mode = :on
68
75
  config.add_formatter('RspecJunitFormatter', 'tmp/elasticsearch-api-junit.xml')
69
76
  end
70
77
 
data/utils/Gemfile CHANGED
@@ -18,10 +18,11 @@
18
18
  source 'https://rubygems.org'
19
19
 
20
20
  gem 'activesupport'
21
- gem 'rest-client'
21
+ gem 'byebug'
22
22
  gem 'coderay'
23
- gem 'multi_json'
24
- gem 'thor'
25
23
  gem 'json'
24
+ gem 'multi_json'
26
25
  gem 'pry'
26
+ gem 'rest-client'
27
27
  gem 'rubocop'
28
+ gem 'thor'
data/utils/README.md CHANGED
@@ -6,7 +6,12 @@ This directory hosts The Generator, a tool that generates the classes for each A
6
6
 
7
7
  ### Generate
8
8
 
9
- To generate the code, you need to run (from this folder):
9
+ To generate the code, you need to have the Elasticsearch REST API spec files in `tmp/rest-api-spec` in the root of the project. You can run a rake task from the root of the project to download the specs corresponding to the current running cluster:
10
+ ```bash
11
+ $ rake elasticsearch:download_artifacts
12
+ ```
13
+
14
+ Once the JSON files have been downloaded, you need to run (from this folder):
10
15
  ```bash
11
16
  $ thor api:code:generate
12
17
  ```
@@ -1,2 +1,4 @@
1
1
  Layout/EndAlignment:
2
2
  AutoCorrect: true
3
+ Metrics/LineLength:
4
+ Max: 160
@@ -66,11 +66,10 @@ module Elasticsearch
66
66
 
67
67
  def __generate_source(api)
68
68
  @current_api = api
69
- @input = FilesHelper.input_dir(api)
70
69
  @output = FilesHelper.output_dir(api)
71
70
 
72
71
  FilesHelper.files(api).each do |filepath|
73
- @path = Pathname(@input.join(filepath))
72
+ @path = Pathname(filepath)
74
73
  @json = MultiJson.load(File.read(@path))
75
74
  @spec = @json.values.first
76
75
  say_status 'json', @path, :yellow
@@ -149,6 +148,7 @@ module Elasticsearch
149
148
 
150
149
  def __http_method
151
150
  return '_id ? Elasticsearch::API::HTTP_PUT : Elasticsearch::API::HTTP_POST' if @endpoint_name == 'index'
151
+ return post_and_get if @endpoint_name == 'count'
152
152
 
153
153
  default_method = @spec['url']['paths'].map { |a| a['methods'] }.flatten.first
154
154
  if @spec['body'] && default_method == 'GET'
@@ -156,19 +156,23 @@ module Elasticsearch
156
156
  if @spec['body']['required']
157
157
  'Elasticsearch::API::HTTP_POST'
158
158
  else
159
- <<~SRC
160
- if arguments[:body]
161
- Elasticsearch::API::HTTP_POST
162
- else
163
- Elasticsearch::API::HTTP_GET
164
- end
165
- SRC
159
+ post_and_get
166
160
  end
167
161
  else
168
162
  "Elasticsearch::API::HTTP_#{default_method}"
169
163
  end
170
164
  end
171
165
 
166
+ def post_and_get
167
+ <<~SRC
168
+ if arguments[:body]
169
+ Elasticsearch::API::HTTP_POST
170
+ else
171
+ Elasticsearch::API::HTTP_GET
172
+ end
173
+ SRC
174
+ end
175
+
172
176
  def __http_path
173
177
  return "\"#{__parse_path(@paths.first)}\"" if @paths.size == 1
174
178
  return termvectors_path if @method_name == 'termvectors'
@@ -195,9 +199,9 @@ module Elasticsearch
195
199
 
196
200
  def __parse_path(path)
197
201
  path.gsub(/^\//, '')
198
- .gsub(/\/$/, '')
199
- .gsub('{', "\#{#{__utils}.__listify(_")
200
- .gsub('}', ')}')
202
+ .gsub(/\/$/, '')
203
+ .gsub('{', "\#{#{__utils}.__listify(_")
204
+ .gsub('}', ')}')
201
205
  end
202
206
 
203
207
  def __path_variables
@@ -227,6 +231,7 @@ module Elasticsearch
227
231
 
228
232
  def docs_helper(name, info)
229
233
  info['type'] = 'String' if info['type'] == 'enum' # Rename 'enums' to 'strings'
234
+ info['type'] = 'Integer' if info['type'] == 'int' # Rename 'int' to 'Integer'
230
235
  tipo = info['type'] ? info['type'].capitalize : 'String'
231
236
  description = info['description'] ? info['description'].strip : '[TODO]'
232
237
  options = info['options'] ? "(options: #{info['options'].join(', ').strip})" : nil
@@ -291,7 +296,7 @@ module Elasticsearch
291
296
  end
292
297
 
293
298
  def __utils
294
- (@current_api == :xpack) ? 'Elasticsearch::API::Utils' : 'Utils'
299
+ @current_api == :xpack ? 'Elasticsearch::API::Utils' : 'Utils'
295
300
  end
296
301
 
297
302
  def run_rubocop(api)
@@ -27,6 +27,7 @@ module Elasticsearch
27
27
  exists
28
28
  indices.exists
29
29
  indices.exists_alias
30
+ indices.exists_index_template
30
31
  indices.exists_template
31
32
  indices.exists_type
32
33
  ].freeze
@@ -37,8 +38,9 @@ module Elasticsearch
37
38
  delete
38
39
  get
39
40
  indices.flush_synced
40
- indices.delete_template
41
41
  indices.delete
42
+ indices.delete_index_template
43
+ indices.delete_template
42
44
  security.get_role
43
45
  security.get_user
44
46
  snapshot.status
@@ -170,6 +172,10 @@ module Elasticsearch
170
172
  SRC
171
173
  end
172
174
 
175
+ def find_structure_body_helper
176
+ bulk_body_helper
177
+ end
178
+
173
179
  def bulk_doc_helper(info)
174
180
  <<~SRC
175
181
  # @option arguments [String|Array] :body #{info}. Array of Strings, Header/Data pairs,
@@ -21,20 +21,47 @@ require_relative '../../../lib/elasticsearch/api/version.rb'
21
21
  module Elasticsearch
22
22
  module API
23
23
  module FilesHelper
24
- OSS_SRC_PATH = '../../../../../tmp/elasticsearch/rest-api-spec/src/main/resources/rest-api-spec/api/'.freeze
24
+ PROJECT_PATH = File.join(File.dirname(__FILE__), '..')
25
+ SRC_PATH = File.join(PROJECT_PATH, '..', '..', '..', 'tmp/rest-api-spec/api/')
25
26
  OSS_OUTPUT_DIR = '../../elasticsearch-api/lib/elasticsearch/api/actions'.freeze
26
-
27
- XPACK_SRC_PATH = '../../../../../tmp/elasticsearch/x-pack/plugin/src/test/resources/rest-api-spec/api'.freeze
28
27
  XPACK_OUTPUT_DIR = '../../elasticsearch-xpack/lib/elasticsearch/xpack/api/actions'.freeze
29
28
 
30
- # Path to directory with JSON API specs
31
- def self.input_dir(api)
32
- input_dir = if api == :xpack
33
- File.expand_path(XPACK_SRC_PATH, __FILE__)
34
- else
35
- File.expand_path(OSS_SRC_PATH, __FILE__)
36
- end
37
- Pathname(input_dir)
29
+ TESTS_DIRECTORIES = {
30
+ oss: "#{PROJECT_PATH}/../../../tmp/rest-api-spec/test/free",
31
+ xpack: "#{PROJECT_PATH}/../../../tmp/rest-api-spec/test/platinum"
32
+ }.freeze
33
+
34
+ # Only get JSON files and remove hidden files
35
+ def self.files(api)
36
+ json_files = if api == :xpack
37
+ xpack_files
38
+ else
39
+ Dir.entries(SRC_PATH) - xpack_files
40
+ end
41
+ json_files.reject do |file|
42
+ File.extname(file) != '.json' ||
43
+ File.basename(file) == '_common.json'
44
+ end.map { |file| "#{SRC_PATH}#{file}" }
45
+ end
46
+
47
+ XPACK_ENDPOINTS = [
48
+ 'autoscaling', 'cross_cluster_replication', 'ccr', 'data_frame_transform_deprecated',
49
+ 'enrich', 'eql', 'fleet', 'ilm', 'logstash', 'migration', 'watcher', 'slm'
50
+ ]
51
+ XPACK_ENDPOINTS_REGEXP = /data_stream|ml_|reload_search_analyzers|transform|freeze|unfreeze/
52
+
53
+ def self.xpack_files
54
+ xpack_tests = Dir.entries(TESTS_DIRECTORIES[:xpack])
55
+ Dir.entries(SRC_PATH).map do |entry|
56
+ filename = entry.split('.').first
57
+ next if filename == 'snapshot'
58
+
59
+ if xpack_tests.include?(filename) ||
60
+ XPACK_ENDPOINTS.include?(filename) ||
61
+ entry.match?(XPACK_ENDPOINTS_REGEXP)
62
+ entry
63
+ end
64
+ end.compact
38
65
  end
39
66
 
40
67
  # Path to directory to copy generated files
@@ -42,15 +69,6 @@ module Elasticsearch
42
69
  api == :xpack ? Pathname(XPACK_OUTPUT_DIR) : Pathname(OSS_OUTPUT_DIR)
43
70
  end
44
71
 
45
- # Only get JSON files and remove hidden files
46
- def self.files(api)
47
- Dir.entries(input_dir(api).to_s).reject do |f|
48
- f.start_with?('.') ||
49
- f.start_with?('_') ||
50
- File.extname(f) != '.json'
51
- end
52
- end
53
-
54
72
  def self.gem_version
55
73
  regex = /([0-9]{1,2}\.[0-9x]{1,2})/
56
74
  Elasticsearch::API::VERSION.match(regex)[0]
@@ -1,3 +1,22 @@
1
+ <%#
2
+ # Licensed to Elasticsearch B.V. under one or more contributor
3
+ # license agreements. See the NOTICE file distributed with
4
+ # this work for additional information regarding copyright
5
+ # ownership. Elasticsearch B.V. licenses this file to you under
6
+ # the Apache License, Version 2.0 (the "License"); you may
7
+ # not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ %>
19
+
1
20
  <%- if @spec['documentation']['description'] -%>
2
21
  <%= ' '*(@namespace_depth+3) %># <%= @spec['documentation']['description'].gsub("\n", "\n#{' '*(@namespace_depth+3)}# ") -%>
3
22
  <%- else %>
@@ -1,3 +1,21 @@
1
+ <%#
2
+ # Licensed to Elasticsearch B.V. under one or more contributor
3
+ # license agreements. See the NOTICE file distributed with
4
+ # this work for additional information regarding copyright
5
+ # ownership. Elasticsearch B.V. licenses this file to you under
6
+ # the Apache License, Version 2.0 (the "License"); you may
7
+ # not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ %>
1
19
  <%- if @endpoint_name == 'indices.stats' %>
2
20
  method = HTTP_GET
3
21
  parts = Utils.__extract_parts arguments, ParamsRegistry.get(:stats_parts)
@@ -1,3 +1,22 @@
1
+ <%#
2
+ # Licensed to Elasticsearch B.V. under one or more contributor
3
+ # license agreements. See the NOTICE file distributed with
4
+ # this work for additional information regarding copyright
5
+ # ownership. Elasticsearch B.V. licenses this file to you under
6
+ # the Apache License, Version 2.0 (the "License"); you may
7
+ # not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ %>
19
+
1
20
  <%- unless @params.empty? -%>
2
21
  <%= ' '*(@namespace_depth+3) %># Register this action with its valid params when the module is loaded.
3
22
  <%= ' '*(@namespace_depth+3) %>#
@@ -1,3 +1,21 @@
1
+ <%#
2
+ # Licensed to Elasticsearch B.V. under one or more contributor
3
+ # license agreements. See the NOTICE file distributed with
4
+ # this work for additional information regarding copyright
5
+ # ownership. Elasticsearch B.V. licenses this file to you under
6
+ # the Apache License, Version 2.0 (the "License"); you may
7
+ # not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ %>
1
19
  <%-
2
20
  case @endpoint_name
3
21
  when 'mtermvectors'
@@ -14,9 +32,9 @@ when 'mtermvectors'
14
32
  <%- else -%>
15
33
  <%= ' '*(@namespace_depth+3) %>body = <%= @spec['body'].nil? ? 'nil' : 'arguments[:body]' %>
16
34
  <%- end -%>
17
- <%- if ['bulk', 'msearch', 'msearch_template'].include? @method_name -%>
35
+ <%- if ['bulk', 'msearch', 'msearch_template', 'find_structure'].include? @method_name -%>
18
36
  <%= self.send("#{@method_name}_body_helper".to_s) %>
19
- headers.merge!("Content-Type" => "application/x-ndjson")
37
+ headers = <%= __utils %>.ndjson_headers(headers)
20
38
  <%= ' '*(@namespace_depth+4) %>perform_request(method, path, params, payload, headers).body
21
39
  <%- elsif @method_name == 'ping' -%>
22
40
  <%= ping_perform_request %>
@@ -1,6 +1,19 @@
1
- # Licensed to Elasticsearch B.V under one or more agreements.
2
- # Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3
- # See the LICENSE file in the project root for more information
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
4
17
 
5
18
  require 'test_helper'
6
19
 
@@ -15,10 +15,6 @@
15
15
  # specific language governing permissions and limitations
16
16
  # under the License.
17
17
 
18
- RUBY_1_8 = defined?(RUBY_VERSION) && RUBY_VERSION < '1.9'
19
-
20
- require 'rubygems' if RUBY_1_8
21
-
22
18
  require 'simplecov' and SimpleCov.start { add_filter "/test|test_/" } if ENV["COVERAGE"]
23
19
 
24
20
  require 'test/unit'