elasticsearch-api 7.5.0 → 7.6.0.pre

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6b881e7cb1f40511b850a1ef10fe4f39047ca62fadb6de31f7d47bb9b9975d5d
4
- data.tar.gz: 7c285a20100e694ad7b5d3806d3b62cbc58341a6b9eaf2f4c88294fc0367692e
3
+ metadata.gz: af3380ec96ce20178b990da023be0a4a6bfe8b75958d3ce27313854583b944bf
4
+ data.tar.gz: 62d8fe93f4c2adffc6cb0b8e6eaaed09192fdadba06329073ba3e12a0ebb6875
5
5
  SHA512:
6
- metadata.gz: 4e6ada0c6484d228af0ea67e66e5ae209ae90b7a4c6e4342c4f6616f206417add4dd03c435854df5d3e3b7d0b14c1af14dfc43cfa8026b6779e1c62933467064
7
- data.tar.gz: 95b8072f025a5b9963bad07951190d9b4123d87f523dcd9e62b7fbb0553740ada93bd02aac89784c672dd62a8584717f3eec1b4f5c54026766193255b403de4c
6
+ metadata.gz: bc0de7b154bcf04f158dfd0f498a3f6e36ff14c84045e82321305a769671de618e3a69b074d674c4eaa1aadc66f3f86268662bda8a28f3e58803a91fa9a1b64c
7
+ data.tar.gz: 92ce16042eec52783770d0601e966c367f013f73fa3559b5ee2e114eeab4b99b988b852ffdcbfadd7a35300d88172a96a51019c1e3cc2302e20a1417a5215382
data/Gemfile CHANGED
@@ -8,19 +8,22 @@ source 'https://rubygems.org'
8
8
  gemspec
9
9
 
10
10
  if File.exist? File.expand_path("../../elasticsearch/elasticsearch.gemspec", __FILE__)
11
- gem 'elasticsearch', :path => File.expand_path("../../elasticsearch", __FILE__), :require => false
11
+ gem 'elasticsearch', path: File.expand_path("../../elasticsearch", __FILE__), require: false
12
12
  end
13
13
 
14
14
  if File.exist? File.expand_path("../../elasticsearch-transport", __FILE__)
15
- gem 'elasticsearch-transport', :path => File.expand_path("../../elasticsearch-transport", __FILE__), :require => true
15
+ gem 'elasticsearch-transport', path: File.expand_path("../../elasticsearch-transport", __FILE__), require: true
16
16
  end
17
17
 
18
18
  if File.exist? File.expand_path("../../elasticsearch-extensions", __FILE__)
19
- gem 'elasticsearch-extensions', :path => File.expand_path("../../elasticsearch-extensions", __FILE__), :require => false
19
+ gem 'elasticsearch-extensions', path: File.expand_path("../../elasticsearch-extensions", __FILE__), require: false
20
20
  end
21
21
 
22
-
23
22
  group :development do
24
23
  gem 'rspec'
25
- gem 'pry-nav'
24
+ if defined?(JRUBY_VERSION)
25
+ gem 'pry-nav'
26
+ else
27
+ gem 'pry-byebug'
28
+ end
26
29
  end
data/Rakefile CHANGED
@@ -69,7 +69,7 @@ namespace :test do
69
69
  es_version_info = client.info['version']
70
70
  build_hash = es_version_info['build_hash']
71
71
  cluster_running = true
72
- rescue Faraday::Error::ConnectionFailed
72
+ rescue Faraday::ConnectionFailed
73
73
  STDERR.puts "[!] Test cluster not running?"
74
74
  cluster_running = false
75
75
  end
@@ -8,72 +8,51 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
8
8
  require 'elasticsearch/api/version'
9
9
 
10
10
  Gem::Specification.new do |s|
11
- s.name = "elasticsearch-api"
11
+ s.name = 'elasticsearch-api'
12
12
  s.version = Elasticsearch::API::VERSION
13
- s.authors = ["Karel Minarik"]
14
- s.email = ["karel.minarik@elasticsearch.org"]
15
- s.summary = "Ruby API for Elasticsearch."
16
- s.homepage = "https://github.com/elasticsearch/elasticsearch-ruby/tree/master/elasticsearch-api"
17
- s.license = "Apache-2.0"
13
+ s.authors = ['Karel Minarik']
14
+ s.email = ['karel.minarik@elasticsearch.org']
15
+ s.summary = 'Ruby API for Elasticsearch.'
16
+ s.homepage = 'https://github.com/elasticsearch/elasticsearch-ruby/tree/master/elasticsearch-api'
17
+ s.license = 'Apache-2.0'
18
18
 
19
19
  s.files = `git ls-files`.split($/)
20
20
  s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
21
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
22
- s.require_paths = ["lib"]
22
+ s.require_paths = ['lib']
23
23
 
24
- s.extra_rdoc_files = [ "README.md", "LICENSE" ]
25
- s.rdoc_options = [ "--charset=UTF-8" ]
24
+ s.extra_rdoc_files = [ 'README.md', 'LICENSE' ]
25
+ s.rdoc_options = [ '--charset=UTF-8' ]
26
26
 
27
- s.required_ruby_version = '>= 1.9'
27
+ s.required_ruby_version = '>= 2.4'
28
28
 
29
- s.add_dependency "multi_json"
29
+ s.add_dependency 'multi_json'
30
30
 
31
- s.add_development_dependency "bundler"
32
-
33
- if defined?(RUBY_VERSION) && RUBY_VERSION > '1.9'
34
- s.add_development_dependency "rake", "~> 11.1"
35
- else
36
- s.add_development_dependency "rake", "< 11.0"
37
- end
38
-
39
- s.add_development_dependency "elasticsearch"
40
- s.add_development_dependency "elasticsearch-transport"
41
-
42
- if defined?(RUBY_VERSION) && RUBY_VERSION > '1.9'
43
- s.add_development_dependency "minitest"
44
- s.add_development_dependency "minitest-reporters"
45
- s.add_development_dependency "elasticsearch-extensions"
46
- end
47
-
48
- s.add_development_dependency "ansi"
49
- s.add_development_dependency "shoulda-context"
50
- s.add_development_dependency "mocha"
51
- s.add_development_dependency "yard"
52
- s.add_development_dependency "pry"
31
+ s.add_development_dependency 'ansi'
32
+ s.add_development_dependency 'bundler'
33
+ s.add_development_dependency 'elasticsearch'
34
+ s.add_development_dependency 'elasticsearch-extensions'
35
+ s.add_development_dependency 'elasticsearch-transport'
36
+ s.add_development_dependency 'minitest'
37
+ s.add_development_dependency 'minitest-reporters'
38
+ s.add_development_dependency 'mocha'
39
+ s.add_development_dependency 'pry'
40
+ s.add_development_dependency 'rake', '~> 11.1'
41
+ s.add_development_dependency 'shoulda-context'
42
+ s.add_development_dependency 'yard'
53
43
 
54
44
  # Gems for testing integrations
55
- s.add_development_dependency "jsonify"
56
- s.add_development_dependency "hashie"
57
-
58
- # Prevent unit test failures on Ruby 1.8
59
- if defined?(RUBY_VERSION) && RUBY_VERSION < '1.9'
60
- s.add_development_dependency "test-unit", '~> 2'
61
- s.add_development_dependency "json", '~> 1.8'
62
- end
63
-
64
- if defined?(RUBY_VERSION) && RUBY_VERSION > '1.9'
65
- s.add_development_dependency "ruby-prof" unless defined?(JRUBY_VERSION) || defined?(Rubinius)
66
- s.add_development_dependency "jbuilder"
67
- s.add_development_dependency "escape_utils" unless defined? JRUBY_VERSION
68
- s.add_development_dependency "simplecov", '~> 0.17', '< 0.18'
69
- s.add_development_dependency "simplecov-rcov"
70
- s.add_development_dependency "cane"
71
- s.add_development_dependency "require-prof" unless defined?(JRUBY_VERSION) || defined?(Rubinius)
72
- end
73
-
74
- if defined?(RUBY_VERSION) && RUBY_VERSION > '2.2'
75
- s.add_development_dependency "test-unit", '~> 2'
76
- end
45
+ s.add_development_dependency 'jsonify'
46
+ s.add_development_dependency 'hashie'
47
+
48
+ s.add_development_dependency 'cane'
49
+ s.add_development_dependency 'escape_utils' unless defined? JRUBY_VERSION
50
+ s.add_development_dependency 'jbuilder'
51
+ s.add_development_dependency 'require-prof' unless defined?(JRUBY_VERSION) || defined?(Rubinius)
52
+ s.add_development_dependency 'simplecov', '~> 0.17', '< 0.18'
53
+ s.add_development_dependency 'simplecov-rcov'
54
+ s.add_development_dependency 'test-unit', '~> 2'
55
+ s.add_development_dependency 'ruby-prof' unless defined?(JRUBY_VERSION) || defined?(Rubinius)
77
56
 
78
57
  s.description = <<-DESC.gsub(/^ /, '')
79
58
  Ruby API for Elasticsearch. See the `elasticsearch` gem for full integration.
@@ -32,7 +32,8 @@ module Elasticsearch
32
32
  :format, # Search, Cat, ...
33
33
  :pretty, # Pretty-print the response
34
34
  :human, # Return numeric values in human readable format
35
- :filter_path # Filter the JSON response
35
+ :filter_path, # Filter the JSON response
36
+ :opaque_id # Use X-Opaque-Id
36
37
  ]
37
38
 
38
39
  HTTP_GET = 'GET'.freeze
@@ -46,7 +46,7 @@ module Elasticsearch
46
46
 
47
47
  body = arguments[:body]
48
48
  if body.is_a? Array
49
- payload = Utils.__bulkify(body)
49
+ payload = Elasticsearch::API::Utils.__bulkify(body)
50
50
  else
51
51
  payload = body
52
52
  end
@@ -26,7 +26,7 @@ module Elasticsearch
26
26
 
27
27
  method = Elasticsearch::API::HTTP_GET
28
28
  path = "_cat/health"
29
- params = Elasticsearch::API::Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
29
+ params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
30
30
  params[:h] = Utils.__listify(params[:h]) if params[:h]
31
31
 
32
32
  body = nil
@@ -11,7 +11,7 @@ module Elasticsearch
11
11
  # @option arguments [List] :index A comma-separated list of index names to limit the returned information
12
12
  # @option arguments [String] :format a short version of the Accept header, e.g. json, yaml
13
13
  # @option arguments [String] :bytes The unit in which to display byte values
14
- # (options: b,k,m,g)
14
+ # (options: b,k,kb,m,mb,g,gb,t,tb,p,pb)
15
15
 
16
16
  # @option arguments [Boolean] :local Return local information, do not retrieve the state from master node (default: false)
17
17
  # @option arguments [Time] :master_timeout Explicit operation timeout for connection to master node
@@ -13,7 +13,7 @@ module Elasticsearch
13
13
 
14
14
  # @option arguments [String] :format a short version of the Accept header, e.g. json, yaml
15
15
  # @option arguments [Boolean] :full_id Return the full node ID instead of the shortened version (default: false)
16
- # @option arguments [Boolean] :local Return local information, do not retrieve the state from master node (default: false)
16
+ # @option arguments [Boolean] :local Calculate the selected nodes using the local cluster state rather than the state from master node (default: false) *Deprecated*
17
17
  # @option arguments [Time] :master_timeout Explicit operation timeout for connection to master node
18
18
  # @option arguments [List] :h Comma-separated list of column names to display
19
19
  # @option arguments [Boolean] :help Return help information
@@ -27,7 +27,7 @@ module Elasticsearch
27
27
 
28
28
  method = Elasticsearch::API::HTTP_GET
29
29
  path = "_cat/pending_tasks"
30
- params = Elasticsearch::API::Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
30
+ params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
31
31
  params[:h] = Utils.__listify(params[:h]) if params[:h]
32
32
 
33
33
  body = nil
@@ -9,6 +9,7 @@ module Elasticsearch
9
9
  #
10
10
  # @option arguments [List] :index A comma-separated list of index names to search; use `_all` or empty string to perform the operation on all indices (*Required*)
11
11
  # @option arguments [List] :type A comma-separated list of document types to search; leave empty to perform the operation on all types
12
+ # @option arguments [String] :analyzer The analyzer to use for the query string
12
13
  # @option arguments [Boolean] :analyze_wildcard Specify whether wildcard and prefix queries should be analyzed (default: false)
13
14
  # @option arguments [String] :default_operator The default operator for query string query (AND or OR)
14
15
  # (options: AND,OR)
@@ -85,6 +86,7 @@ module Elasticsearch
85
86
  #
86
87
  # @since 6.2.0
87
88
  ParamsRegistry.register(:delete_by_query, [
89
+ :analyzer,
88
90
  :analyze_wildcard,
89
91
  :default_operator,
90
92
  :df,
@@ -0,0 +1,26 @@
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
4
+
5
+ module Elasticsearch
6
+ module API
7
+ module Actions
8
+ # Returns all script contexts.
9
+ #
10
+
11
+ #
12
+ # @see [TODO]
13
+ #
14
+ def get_script_context(arguments = {})
15
+ arguments = arguments.clone
16
+
17
+ method = Elasticsearch::API::HTTP_GET
18
+ path = "_script_context"
19
+ params = {}
20
+
21
+ body = nil
22
+ perform_request(method, path, params, body).body
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
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
4
+
5
+ module Elasticsearch
6
+ module API
7
+ module Actions
8
+ # Returns available script types, languages and contexts
9
+ #
10
+
11
+ #
12
+ # @see [TODO]
13
+ #
14
+ def get_script_languages(arguments = {})
15
+ arguments = arguments.clone
16
+
17
+ method = Elasticsearch::API::HTTP_GET
18
+ path = "_script_language"
19
+ params = {}
20
+
21
+ body = nil
22
+ perform_request(method, path, params, body).body
23
+ end
24
+ end
25
+ end
26
+ end
@@ -6,7 +6,7 @@ module Elasticsearch
6
6
  module API
7
7
  module Indices
8
8
  module Actions
9
- # Performs a synced flush operation on one or more indices.
9
+ # Performs a synced flush operation on one or more indices. Synced flush is deprecated and will be removed in 8.0. Use flush instead
10
10
  #
11
11
  # @option arguments [List] :index A comma-separated list of index names; use `_all` or empty string for all indices
12
12
  # @option arguments [Boolean] :ignore_unavailable Whether specified concrete indices should be ignored when unavailable (missing or closed)
@@ -39,12 +39,10 @@ module Elasticsearch
39
39
  method = Elasticsearch::API::HTTP_PUT
40
40
  path = if _index && _type
41
41
  "#{Utils.__listify(_index)}/#{Utils.__listify(_type)}/_mappings"
42
+ elsif _index
43
+ "#{Utils.__listify(_index)}/_mapping"
42
44
  elsif _type
43
45
  "_mappings/#{Utils.__listify(_type)}"
44
- elsif _index
45
- "#{Utils.__listify(_index)}/_mappings"
46
- else
47
- "_mapping/#{Utils.__listify(_type)}"
48
46
  end
49
47
  params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
50
48
 
@@ -12,9 +12,7 @@ module Elasticsearch
12
12
  # @option arguments [Boolean] :include_type_name Whether a type should be returned in the body of the mappings.
13
13
  # @option arguments [Number] :order The order for this template when merging multiple matching ones (higher numbers are merged later, overriding the lower numbers)
14
14
  # @option arguments [Boolean] :create Whether the index template should only be added if new or can also replace an existing one
15
- # @option arguments [Time] :timeout Explicit operation timeout
16
15
  # @option arguments [Time] :master_timeout Specify timeout for connection to master
17
- # @option arguments [Boolean] :flat_settings Return settings in flat format (default: false)
18
16
 
19
17
  # @option arguments [Hash] :body The template definition (*Required*)
20
18
  #
@@ -43,9 +41,7 @@ module Elasticsearch
43
41
  :include_type_name,
44
42
  :order,
45
43
  :create,
46
- :timeout,
47
- :master_timeout,
48
- :flat_settings
44
+ :master_timeout
49
45
  ].freeze)
50
46
  end
51
47
  end
@@ -15,6 +15,7 @@ module Elasticsearch
15
15
  # @option arguments [Boolean] :typed_keys Specify whether aggregation and suggester names should be prefixed by their respective types in the response
16
16
  # @option arguments [Number] :max_concurrent_searches Controls the maximum number of concurrent searches the multi search api will execute
17
17
  # @option arguments [Boolean] :rest_total_hits_as_int Indicates whether hits.total should be rendered as an integer or an object in the rest search response
18
+ # @option arguments [Boolean] :ccs_minimize_roundtrips Indicates whether network round-trips should be minimized as part of cross-cluster search requests execution
18
19
 
19
20
  # @option arguments [Hash] :body The request definitions (metadata-search request definition pairs), separated by newlines (*Required*)
20
21
  #
@@ -65,7 +66,8 @@ module Elasticsearch
65
66
  :search_type,
66
67
  :typed_keys,
67
68
  :max_concurrent_searches,
68
- :rest_total_hits_as_int
69
+ :rest_total_hits_as_int,
70
+ :ccs_minimize_roundtrips
69
71
  ].freeze)
70
72
  end
71
73
  end
@@ -13,6 +13,9 @@ module Elasticsearch
13
13
  # @option arguments [String] :expand_wildcards Whether to expand wildcard expression to concrete indices that are open, closed or both.
14
14
  # (options: open,closed,none,all)
15
15
 
16
+ # @option arguments [String] :search_type Search operation type
17
+ # (options: query_then_fetch,dfs_query_then_fetch)
18
+
16
19
  # @option arguments [Hash] :body The ranking evaluation search definition, including search requests, document ratings and ranking metric definition. (*Required*)
17
20
  #
18
21
  # @see https://www.elastic.co/guide/en/elasticsearch/reference/7.5/search-rank-eval.html
@@ -42,7 +45,8 @@ module Elasticsearch
42
45
  ParamsRegistry.register(:rank_eval, [
43
46
  :ignore_unavailable,
44
47
  :allow_no_indices,
45
- :expand_wildcards
48
+ :expand_wildcards,
49
+ :search_type
46
50
  ].freeze)
47
51
  end
48
52
  end
@@ -25,6 +25,7 @@ module Elasticsearch
25
25
  # @option arguments [Boolean] :profile Specify whether to profile the query execution
26
26
  # @option arguments [Boolean] :typed_keys Specify whether aggregation and suggester names should be prefixed by their respective types in the response
27
27
  # @option arguments [Boolean] :rest_total_hits_as_int Indicates whether hits.total should be rendered as an integer or an object in the rest search response
28
+ # @option arguments [Boolean] :ccs_minimize_roundtrips Indicates whether network round-trips should be minimized as part of cross-cluster search requests execution
28
29
 
29
30
  # @option arguments [Hash] :body The search definition template and its params (*Required*)
30
31
  #
@@ -73,7 +74,8 @@ module Elasticsearch
73
74
  :explain,
74
75
  :profile,
75
76
  :typed_keys,
76
- :rest_total_hits_as_int
77
+ :rest_total_hits_as_int,
78
+ :ccs_minimize_roundtrips
77
79
  ].freeze)
78
80
  end
79
81
  end
@@ -4,6 +4,6 @@
4
4
 
5
5
  module Elasticsearch
6
6
  module API
7
- VERSION = "7.5.0"
7
+ VERSION = "7.6.0.pre"
8
8
  end
9
9
  end
@@ -0,0 +1,61 @@
1
+ # Rest API YAML Spec Runner
2
+
3
+ The file that traverses the yaml files and loads a **TestFile** object per each of them:
4
+ `elasticsearch-api/spec/elasticsearch/api/rest_api_yaml_spec.rb`
5
+
6
+ You can use the SINGLE_TEST env variable to run just one test, or add code like this on the first line of the tests.each block:
7
+ ```ruby
8
+ next unless file =~ /indices.put_mapping\/all_path_options_with_types.yml/
9
+ ```
10
+
11
+ #### TestFile object
12
+ Class representing a single test file. Contains setup, teardown and tests.
13
+ `../api-spec-testing/test_file.rb`
14
+
15
+ #### Test object
16
+ Every single test in the test file is represented in the Test object.
17
+ `../api-spec-testing/test_file/test.rb`
18
+
19
+ #### TaskGroup objects
20
+
21
+ Tests are ordered in task groups, an array of TaskGroup objects.
22
+ `../api-spec-testing/test_file/task_group.rb`
23
+
24
+ Task Groups are a representation of a block of actions consisting of 'do' actions and their verifications. e.g.:
25
+ ```yaml
26
+ - do:
27
+ index:
28
+ index: test-index
29
+ id: 1
30
+ body: { foo: bar }
31
+
32
+ - match: { _index: test-index }
33
+ - match: { _id: "1"}
34
+ - match: { _version: 1}
35
+ ```
36
+
37
+ **Before** each test, the spec runner runs `clear_data` on the test_file. This clears indices, index templates, snapshots and repositories. For xpack it also clears roles, users, privileges, datafeeds, ml_jobs and more.
38
+
39
+ **After** each test, it runs the test file teardown and `clear_data` again.
40
+
41
+ For each TaskGroup, it sees what's in the task group definition and runs an expectation test.
42
+
43
+ # Rest YAML tests Helper
44
+
45
+ `elasticsearch-api/spec/rest_yaml_tests_helper.rb`
46
+
47
+ - `ADMIN_CLIENT` is defined here.
48
+ - `SINGLE_TEST` is defined here.
49
+ - Skipped tests are listed here
50
+
51
+ # Spec Helper
52
+
53
+ - `DEFAULT_CLIENT` is defined here
54
+
55
+ # RSpec Matchers
56
+
57
+ The tests use custom [RSpec Matchers](https://www.rubydoc.info/gems/rspec-expectations/RSpec/Matchers) defined in `api-spec-testing/rspec_matchers.rb`.
58
+
59
+ # Enable Logging
60
+
61
+ To enable logging, set the environment `QUIET` to false before running the tests. In CI, this is located in the [Dockerfile](https://github.com/elastic/elasticsearch-ruby/blob/master/.ci/Dockerfile). The environment variable is evaluated in the Rest YAML tests Helper file.
@@ -6,29 +6,23 @@ require 'spec_helper'
6
6
  require 'rest_yaml_tests_helper'
7
7
 
8
8
  describe 'Rest API YAML tests' do
9
-
9
+ # Traverse YAML files and create TestFile object:
10
10
  REST_API_YAML_FILES.each do |file|
11
-
12
11
  test_file = Elasticsearch::RestAPIYAMLTests::TestFile.new(file, REST_API_YAML_SKIP_FEATURES)
13
12
 
14
13
  context "#{file.gsub("#{YAML_FILES_DIRECTORY}/", '')}" do
15
-
16
14
  test_file.tests.each do |test|
17
15
 
18
16
  context "#{test.description}" do
19
-
20
17
  if test.skip_test?(ADMIN_CLIENT)
21
18
  skip 'Test contains feature(s) not yet supported or version is not satisfied'
22
-
23
19
  else
24
-
25
20
  let(:client) do
26
21
  DEFAULT_CLIENT
27
22
  end
28
23
 
29
24
  # Runs once before each test in a test file
30
25
  before(:all) do
31
- # Runs once before each test in a test file
32
26
  Elasticsearch::RestAPIYAMLTests::TestFile.clear_data(ADMIN_CLIENT)
33
27
  test_file.setup(ADMIN_CLIENT)
34
28
  end
@@ -39,21 +33,18 @@ describe 'Rest API YAML tests' do
39
33
  end
40
34
 
41
35
  test.task_groups.each do |task_group|
42
-
43
36
  before do
44
37
  task_group.run(client)
45
38
  end
46
39
 
47
40
  # 'catch' is in the task group definition
48
41
  if task_group.catch_exception?
49
-
50
42
  it 'sends the request and throws the expected error' do
51
43
  expect(task_group.exception).to match_error(task_group.expected_exception_message)
52
44
  end
53
45
 
54
46
  # 'match' on error description is in the task group definition
55
47
  if task_group.has_match_clauses?
56
-
57
48
  task_group.match_clauses.each do |match|
58
49
  it 'contains the expected error in the request response' do
59
50
  expect(task_group.exception.message).to match(Regexp.new(Regexp.escape(match['match'].values.first.to_s)))
@@ -64,7 +55,6 @@ describe 'Rest API YAML tests' do
64
55
 
65
56
  # 'match' is in the task group definition
66
57
  if task_group.has_match_clauses?
67
-
68
58
  task_group.match_clauses.each do |match|
69
59
  it "has the expected value (#{match['match'].values.join(',')}) in the response field (#{match['match'].keys.join(',')})" do
70
60
  expect(task_group.response).to match_response(match['match'], test)
@@ -74,7 +64,6 @@ describe 'Rest API YAML tests' do
74
64
 
75
65
  # 'length' is in the task group definition
76
66
  if task_group.has_length_match_clauses?
77
-
78
67
  task_group.length_match_clauses.each do |match|
79
68
  it "the '#{match['length'].keys.join(',')}' field have the expected length" do
80
69
  expect(task_group.response).to match_response_field_length(match['length'], test)
@@ -84,7 +73,6 @@ describe 'Rest API YAML tests' do
84
73
 
85
74
  # 'is_true' is in the task group definition
86
75
  if task_group.has_true_clauses?
87
-
88
76
  task_group.true_clauses.each do |match|
89
77
  it "sends the request and the '#{match['is_true']}' field is set to true" do
90
78
  expect(task_group.response).to match_true_field(match['is_true'], test)
@@ -94,7 +82,6 @@ describe 'Rest API YAML tests' do
94
82
 
95
83
  # 'is_false' is in the task group definition
96
84
  if task_group.has_false_clauses?
97
-
98
85
  task_group.false_clauses.each do |match|
99
86
  it "sends the request and the '#{match['is_false']}' field is set to true" do
100
87
  expect(task_group.response).to match_false_field(match['is_false'], test)
@@ -104,7 +91,6 @@ describe 'Rest API YAML tests' do
104
91
 
105
92
  # 'gte' is in the task group definition
106
93
  if task_group.has_gte_clauses?
107
-
108
94
  task_group.gte_clauses.each do |match|
109
95
  it "sends the request and the '#{match['gte']}' field is greater than or equal to the expected value" do
110
96
  expect(task_group.response).to match_gte_field(match['gte'], test)
@@ -114,7 +100,6 @@ describe 'Rest API YAML tests' do
114
100
 
115
101
  # 'gt' is in the task group definition
116
102
  if task_group.has_gt_clauses?
117
-
118
103
  task_group.gt_clauses.each do |match|
119
104
  it "sends the request and the '#{match['gt']}' field is greater than the expected value" do
120
105
  expect(task_group.response).to match_gt_field(match['gt'], test)
@@ -124,7 +109,6 @@ describe 'Rest API YAML tests' do
124
109
 
125
110
  # 'lte' is in the task group definition
126
111
  if task_group.has_lte_clauses?
127
-
128
112
  task_group.lte_clauses.each do |match|
129
113
  it "sends the request and the '#{match['lte']}' field is less than or equal to the expected value" do
130
114
  expect(task_group.response).to match_lte_field(match['lte'], test)
@@ -134,7 +118,6 @@ describe 'Rest API YAML tests' do
134
118
 
135
119
  # 'lt' is in the task group definition
136
120
  if task_group.has_lt_clauses?
137
-
138
121
  task_group.lt_clauses.each do |match|
139
122
  it "sends the request and the '#{match['lt']}' field is less than the expected value" do
140
123
  expect(task_group.response).to match_lt_field(match['lt'], test)
@@ -11,10 +11,11 @@ PROJECT_PATH = File.join(File.dirname(__FILE__), '..', '..')
11
11
 
12
12
  if hosts = ELASTICSEARCH_URL
13
13
  split_hosts = hosts.split(',').map do |host|
14
- /(http\:\/\/)?(\S+)/.match(host)[2]
14
+ /(http\:\/\/)?\S+/.match(host)
15
15
  end
16
-
17
- TEST_HOST, TEST_PORT = split_hosts.first.split(':')
16
+ uri = URI.parse(split_hosts.first[0])
17
+ TEST_HOST = uri.host
18
+ TEST_PORT = uri.port
18
19
  else
19
20
  TEST_HOST, TEST_PORT = 'localhost', '9200'
20
21
  end
@@ -2,7 +2,11 @@
2
2
  # Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3
3
  # See the LICENSE file in the project root for more information
4
4
 
5
- require 'pry-nav'
5
+ if defined?(JRUBY_VERSION)
6
+ require 'pry-nav'
7
+ else
8
+ require 'pry-byebug'
9
+ end
6
10
  require 'yaml'
7
11
  require 'jbuilder'
8
12
  require 'jsonify'
@@ -0,0 +1,41 @@
1
+ # Utils
2
+
3
+ ## The Generator
4
+
5
+ This directory hosts The Generator, a tool that generates the classes for each API endpoint from the [Elasticsearch REST API JSON Specification](https://github.com/elastic/elasticsearch/tree/master/rest-api-spec).
6
+
7
+ ### Generate
8
+
9
+ To generate the code, you need to run (from this folder):
10
+ ```bash
11
+ $ thor api:code:generate
12
+ ```
13
+
14
+ - The oss Ruby code will be generated in `elasticsearch-api/lib/elasticsearch/api/actions`.
15
+ - The xpack Ruby code will be generated in `elasticsearch-xpack/lib/elasticsearch/xpack/api/actions`.
16
+ - The generator runs Rubocop to autolint and clean up the generated files.
17
+
18
+ Alternatively, you can pass in `oss` or `xpack` as parameters to generate only one of the 2 sets of endpoints:
19
+
20
+ ```bash
21
+ $ thor api:code:generate --api=xpack
22
+ $ thor api:code:generate --api=oss
23
+ ```
24
+
25
+ ### Development
26
+
27
+ The main entry point is `generate_source.rb`, which contains a class that implements a Thor task: `generate`:
28
+
29
+ ```
30
+ $ thor api:code:generate
31
+ ```
32
+
33
+ It uses [Thor::Actions](https://github.com/erikhuda/thor/wiki/Actions)' `template` method and `templates/method.erb` to generate the final code. The `generator` directory contains some helpers used to generate the code. The ERB template is split into partials and you can find all ERB files in the `templates` directory.
34
+
35
+ There's also a lister task:
36
+
37
+ ```
38
+ $ thor api:list
39
+ ```
40
+
41
+ It's implemented in `lister.rb` and it lists all the REST API endpoints from the JSON specification.
@@ -34,18 +34,28 @@ module Elasticsearch
34
34
  __root = Pathname(File.expand_path('../../..', __FILE__))
35
35
 
36
36
  desc 'generate', 'Generate source code and tests from the REST API JSON specification'
37
- method_option :verbose, type: :boolean, default: false, desc: 'Output more information'
38
- method_option :tests, type: :boolean, default: false, desc: 'Generate test files'
39
- method_option :xpack, type: :boolean, default: false, desc: 'Generate X-Pack'
40
-
37
+ method_option :verbose, type: :boolean, default: false, desc: 'Output more information'
38
+ method_option :tests, type: :boolean, default: false, desc: 'Generate test files'
39
+ method_option :api, type: :array, default: %w[oss xpack], desc: 'APIs to generate (oss, x-pack)'
41
40
  def generate
42
41
  self.class.source_root File.expand_path(__dir__)
43
- @xpack = options[:xpack]
42
+ @xpack = options[:api].include? 'xpack'
43
+ @oss = options[:api].include? 'oss'
44
+
45
+ __generate_source(:xpack) if @xpack
46
+ __generate_source(:oss) if @oss
47
+ # -- Tree output
48
+ print_tree if options[:verbose]
49
+ end
50
+
51
+ private
44
52
 
45
- @input = FilesHelper.input_dir(@xpack)
46
- @output = FilesHelper.output_dir(@xpack)
53
+ def __generate_source(api)
54
+ @current_api = api
55
+ @input = FilesHelper.input_dir(api)
56
+ @output = FilesHelper.output_dir(api)
47
57
 
48
- FilesHelper.files(@xpack).each do |filepath|
58
+ FilesHelper.files(api).each do |filepath|
49
59
  @path = Pathname(@input.join(filepath))
50
60
  @json = MultiJson.load(File.read(@path))
51
61
  @spec = @json.values.first
@@ -83,17 +93,12 @@ module Elasticsearch
83
93
  puts
84
94
  end
85
95
 
86
- run_rubocop
87
-
88
- # -- Tree output
89
- print_tree if options[:verbose]
96
+ run_rubocop(api)
90
97
  end
91
98
 
92
- private
93
-
94
99
  def __full_namespace
95
100
  names = @endpoint_name.split('.')
96
- if @xpack
101
+ if @current_api == :xpack
97
102
  names = (names.first == 'xpack' ? names : ['xpack', names].flatten)
98
103
  # Return an array with 'ml' renamed to 'machine_learning' and 'ilm' to
99
104
  # 'index_lifecycle_management'
@@ -149,12 +154,12 @@ module Elasticsearch
149
154
  return termvectors_path if @method_name == 'termvectors'
150
155
 
151
156
  result = ''
152
- anchor_string = ''
157
+ anchor_string = []
153
158
  @paths.sort { |a, b| b.length <=> a.length }.each_with_index do |path, i|
154
159
  var_string = __extract_path_variables(path).map { |var| "_#{var}" }.join(' && ')
155
- next if anchor_string == var_string
160
+ next if anchor_string.include? var_string
156
161
 
157
- anchor_string = var_string
162
+ anchor_string << var_string
158
163
  result += if i.zero?
159
164
  "if #{var_string}\n"
160
165
  elsif (i == @paths.size - 1) || var_string.empty?
@@ -238,11 +243,11 @@ module Elasticsearch
238
243
  end
239
244
 
240
245
  def __utils
241
- @xpack ? 'Elasticsearch::API::Utils' : 'Utils'
246
+ (@current_api == :xpack) ? 'Elasticsearch::API::Utils' : 'Utils'
242
247
  end
243
248
 
244
- def run_rubocop
245
- system("rubocop --format autogenconf -x #{FilesHelper::output_dir(@xpack)}")
249
+ def run_rubocop(api)
250
+ system("rubocop --format autogenconf -x #{FilesHelper::output_dir(api)}")
246
251
  end
247
252
  end
248
253
  end
@@ -64,6 +64,12 @@ module Elasticsearch
64
64
  COMPLEX_IGNORE_404.include? endpoint
65
65
  end
66
66
 
67
+ def module_name_helper(name)
68
+ return name.upcase if %w[sql ssl].include? name
69
+
70
+ name.split("_").map(&:capitalize).join
71
+ end
72
+
67
73
  def termvectors_path
68
74
  <<~SRC
69
75
  if _index && _type && _id
@@ -146,7 +152,7 @@ module Elasticsearch
146
152
  def bulk_body_helper
147
153
  <<~SRC
148
154
  if body.is_a? Array
149
- payload = Utils.__bulkify(body)
155
+ payload = Elasticsearch::API::Utils.__bulkify(body)
150
156
  else
151
157
  payload = body
152
158
  end
@@ -10,8 +10,8 @@ module Elasticsearch
10
10
  XPACK_OUTPUT_DIR = '../../elasticsearch-xpack/lib/elasticsearch/xpack/api/actions'.freeze
11
11
 
12
12
  # Path to directory with JSON API specs
13
- def self.input_dir(xpack = false)
14
- input_dir = if xpack
13
+ def self.input_dir(api)
14
+ input_dir = if api == :xpack
15
15
  File.expand_path(XPACK_SRC_PATH, __FILE__)
16
16
  else
17
17
  File.expand_path(OSS_SRC_PATH, __FILE__)
@@ -20,13 +20,13 @@ module Elasticsearch
20
20
  end
21
21
 
22
22
  # Path to directory to copy generated files
23
- def self.output_dir(xpack = false)
24
- xpack ? Pathname(XPACK_OUTPUT_DIR) : Pathname(OSS_OUTPUT_DIR)
23
+ def self.output_dir(api)
24
+ api == :xpack ? Pathname(XPACK_OUTPUT_DIR) : Pathname(OSS_OUTPUT_DIR)
25
25
  end
26
26
 
27
27
  # Only get JSON files and remove hidden files
28
- def self.files(xpack = false)
29
- Dir.entries(input_dir(xpack).to_s).reject do |f|
28
+ def self.files(api)
29
+ Dir.entries(input_dir(api).to_s).reject do |f|
30
30
  f.start_with?('.') ||
31
31
  f.start_with?('_') ||
32
32
  File.extname(f) != '.json'
@@ -3,12 +3,12 @@
3
3
  # See the LICENSE file in the project root for more information
4
4
 
5
5
  module Elasticsearch
6
- <%- if @xpack -%>
6
+ <%- if @current_api == :xpack -%>
7
7
  <%= ' '*(@namespace_depth) %>module XPack
8
8
  <%- end %>
9
9
  <%= ' '*(@namespace_depth) %>module API
10
10
  <%- @module_namespace.each_with_index do |name, i| -%>
11
- <%= ' '*i %>module <%= name.split("_").map(&:capitalize).join %>
11
+ <%= ' '*i %>module <%= module_name_helper(name) %>
12
12
  <%- end -%>
13
13
  <%= ' '*(@namespace_depth+2) %>module Actions
14
14
  <%= ERB.new(File.new("./thor/templates/_documentation_top.erb").read, trim_mode: '-').result(binding) -%>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticsearch-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.5.0
4
+ version: 7.6.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karel Minarik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-26 00:00:00.000000000 Z
11
+ date: 2020-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: bundler
28
+ name: ansi
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,19 +39,19 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rake
42
+ name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '11.1'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '11.1'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: elasticsearch
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: elasticsearch-transport
70
+ name: elasticsearch-extensions
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: minitest
84
+ name: elasticsearch-transport
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
@@ -95,7 +95,7 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: minitest-reporters
98
+ name: minitest
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ">="
@@ -109,7 +109,7 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: elasticsearch-extensions
112
+ name: minitest-reporters
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - ">="
@@ -123,7 +123,7 @@ dependencies:
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
- name: ansi
126
+ name: mocha
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - ">="
@@ -137,7 +137,7 @@ dependencies:
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
- name: shoulda-context
140
+ name: pry
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - ">="
@@ -151,7 +151,21 @@ dependencies:
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  - !ruby/object:Gem::Dependency
154
- name: mocha
154
+ name: rake
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '11.1'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '11.1'
167
+ - !ruby/object:Gem::Dependency
168
+ name: shoulda-context
155
169
  requirement: !ruby/object:Gem::Requirement
156
170
  requirements:
157
171
  - - ">="
@@ -179,7 +193,7 @@ dependencies:
179
193
  - !ruby/object:Gem::Version
180
194
  version: '0'
181
195
  - !ruby/object:Gem::Dependency
182
- name: pry
196
+ name: jsonify
183
197
  requirement: !ruby/object:Gem::Requirement
184
198
  requirements:
185
199
  - - ">="
@@ -193,7 +207,7 @@ dependencies:
193
207
  - !ruby/object:Gem::Version
194
208
  version: '0'
195
209
  - !ruby/object:Gem::Dependency
196
- name: jsonify
210
+ name: hashie
197
211
  requirement: !ruby/object:Gem::Requirement
198
212
  requirements:
199
213
  - - ">="
@@ -207,7 +221,7 @@ dependencies:
207
221
  - !ruby/object:Gem::Version
208
222
  version: '0'
209
223
  - !ruby/object:Gem::Dependency
210
- name: hashie
224
+ name: cane
211
225
  requirement: !ruby/object:Gem::Requirement
212
226
  requirements:
213
227
  - - ">="
@@ -221,7 +235,7 @@ dependencies:
221
235
  - !ruby/object:Gem::Version
222
236
  version: '0'
223
237
  - !ruby/object:Gem::Dependency
224
- name: ruby-prof
238
+ name: escape_utils
225
239
  requirement: !ruby/object:Gem::Requirement
226
240
  requirements:
227
241
  - - ">="
@@ -249,7 +263,7 @@ dependencies:
249
263
  - !ruby/object:Gem::Version
250
264
  version: '0'
251
265
  - !ruby/object:Gem::Dependency
252
- name: escape_utils
266
+ name: require-prof
253
267
  requirement: !ruby/object:Gem::Requirement
254
268
  requirements:
255
269
  - - ">="
@@ -297,21 +311,21 @@ dependencies:
297
311
  - !ruby/object:Gem::Version
298
312
  version: '0'
299
313
  - !ruby/object:Gem::Dependency
300
- name: cane
314
+ name: test-unit
301
315
  requirement: !ruby/object:Gem::Requirement
302
316
  requirements:
303
- - - ">="
317
+ - - "~>"
304
318
  - !ruby/object:Gem::Version
305
- version: '0'
319
+ version: '2'
306
320
  type: :development
307
321
  prerelease: false
308
322
  version_requirements: !ruby/object:Gem::Requirement
309
323
  requirements:
310
- - - ">="
324
+ - - "~>"
311
325
  - !ruby/object:Gem::Version
312
- version: '0'
326
+ version: '2'
313
327
  - !ruby/object:Gem::Dependency
314
- name: require-prof
328
+ name: ruby-prof
315
329
  requirement: !ruby/object:Gem::Requirement
316
330
  requirements:
317
331
  - - ">="
@@ -324,20 +338,6 @@ dependencies:
324
338
  - - ">="
325
339
  - !ruby/object:Gem::Version
326
340
  version: '0'
327
- - !ruby/object:Gem::Dependency
328
- name: test-unit
329
- requirement: !ruby/object:Gem::Requirement
330
- requirements:
331
- - - "~>"
332
- - !ruby/object:Gem::Version
333
- version: '2'
334
- type: :development
335
- prerelease: false
336
- version_requirements: !ruby/object:Gem::Requirement
337
- requirements:
338
- - - "~>"
339
- - !ruby/object:Gem::Version
340
- version: '2'
341
341
  description: 'Ruby API for Elasticsearch. See the `elasticsearch` gem for full integration.
342
342
 
343
343
  '
@@ -405,6 +405,8 @@ files:
405
405
  - lib/elasticsearch/api/actions/field_caps.rb
406
406
  - lib/elasticsearch/api/actions/get.rb
407
407
  - lib/elasticsearch/api/actions/get_script.rb
408
+ - lib/elasticsearch/api/actions/get_script_context.rb
409
+ - lib/elasticsearch/api/actions/get_script_languages.rb
408
410
  - lib/elasticsearch/api/actions/get_source.rb
409
411
  - lib/elasticsearch/api/actions/index.rb
410
412
  - lib/elasticsearch/api/actions/indices/analyze.rb
@@ -509,6 +511,7 @@ files:
509
511
  - lib/elasticsearch/api/namespace/tasks.rb
510
512
  - lib/elasticsearch/api/utils.rb
511
513
  - lib/elasticsearch/api/version.rb
514
+ - spec/README.md
512
515
  - spec/elasticsearch/api/actions/abort_benchmark_spec.rb
513
516
  - spec/elasticsearch/api/actions/benchmark_spec.rb
514
517
  - spec/elasticsearch/api/actions/bulk_spec.rb
@@ -641,6 +644,7 @@ files:
641
644
  - test/integration/yaml_test_runner.rb
642
645
  - test/test_helper.rb
643
646
  - utils/Gemfile
647
+ - utils/README.md
644
648
  - utils/Thorfile
645
649
  - utils/thor/generate_source.rb
646
650
  - utils/thor/generator/endpoint_specifics.rb
@@ -666,18 +670,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
666
670
  requirements:
667
671
  - - ">="
668
672
  - !ruby/object:Gem::Version
669
- version: '1.9'
673
+ version: '2.4'
670
674
  required_rubygems_version: !ruby/object:Gem::Requirement
671
675
  requirements:
672
- - - ">="
676
+ - - ">"
673
677
  - !ruby/object:Gem::Version
674
- version: '0'
678
+ version: 1.3.1
675
679
  requirements: []
676
- rubygems_version: 3.0.6
680
+ rubygems_version: 3.1.2
677
681
  signing_key:
678
682
  specification_version: 4
679
683
  summary: Ruby API for Elasticsearch.
680
684
  test_files:
685
+ - spec/README.md
681
686
  - spec/elasticsearch/api/actions/abort_benchmark_spec.rb
682
687
  - spec/elasticsearch/api/actions/benchmark_spec.rb
683
688
  - spec/elasticsearch/api/actions/bulk_spec.rb