Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update generator #2594

Merged
merged 11 commits into from
Mar 13, 2025
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .github/make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ docker run \
-u "$(id -u)" \
--env "RUBY_VERSION=${RUBY_VERSION}" \
--env "WORKFLOW=${WORKFLOW}" \
--env "CLIENTS_GITHUB_TOKEN=${CLIENTS_GITHUB_TOKEN}" \
--name test-runner \
--volume "${repo}:/usr/src/app" \
--rm \
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ profile/**/data/*.json
parsed_alternative_report.json
.byebug_history
build/
*.gem
*.gem
elastic-client-generator-ruby
7 changes: 6 additions & 1 deletion CHANGELOG-9.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Gem

The size of both `elasticsearch` and `elasticsearch-api` gems will be smaller, since some unnecessary files that were being included in the gem have been removed.
The size of both `elasticsearch` and `elasticsearch-api` gems will be smaller, since some unnecessary files that were being included in the gem have been removed. There's also been a lot of old code cleanup for `9.x`.

The required Ruby version is set to `2.6` to keep compatiblity wit JRuby 9.3. However, we only test the code against currently supported Ruby versions.

Expand All @@ -12,6 +12,11 @@ The CI build now runs tests to ensure compatibility with Elasticsearch Serverles

## Elasticsearch API

* The source code is now based on `elasticsearch-specification`, so the API documentation is much more detailed and extensive.
* Scroll APIs: Since sending the `scroll_id` as a parameter was deprecated, now it needs to be sent in the body for `clear_scroll`, `scroll`.
* `indices.get_field_mapping` - `:fields` is a required parameter.
* The functions in `utils.rb` that had names starting with double underscore have been renamed to remove these.

### Development

#### Testing
Expand Down
1 change: 1 addition & 0 deletions elasticsearch-api/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*.rbc
.bundle
.config
.env
.yardoc
Gemfile.lock
InstalledFiles
Expand Down
134 changes: 78 additions & 56 deletions elasticsearch-api/lib/elasticsearch/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,80 +15,102 @@
# specific language governing permissions and limitations
# under the License.

require "cgi"
require "multi_json"

require "elasticsearch/api/version"
require "elasticsearch/api/namespace/common"
require "elasticsearch/api/utils"
require 'cgi'
require 'multi_json'
require 'elasticsearch/api/version'
require 'elasticsearch/api/utils'
require 'elasticsearch/api/response'

Dir[ File.expand_path('../api/actions/**/*.rb', __FILE__) ].each { |f| require f }
Dir[ File.expand_path('../api/namespace/**/*.rb', __FILE__) ].each { |f| require f }
Dir[File.expand_path('api/actions/**/*.rb', __dir__)].each { |f| require f }

module Elasticsearch
# This is the main module for including all API endpoint functions
# It includes the namespace modules from ./api/actions
module API
include Elasticsearch::API::Actions
DEFAULT_SERIALIZER = MultiJson

HTTP_GET = 'GET'.freeze
HTTP_HEAD = 'HEAD'.freeze
HTTP_POST = 'POST'.freeze
HTTP_PUT = 'PUT'.freeze
HTTP_DELETE = 'DELETE'.freeze
UNDERSCORE_SEARCH = '_search'.freeze
UNDERSCORE_ALL = '_all'.freeze
DEFAULT_DOC = '_doc'.freeze

# Auto-include all namespaces in the receiver
module CommonClient
attr_reader :client

def initialize(client)
@client = client
end

def perform_request(method, path, params = {}, body = nil, headers = nil, request_opts = {})
client.perform_request(method, path, params, body, headers, request_opts)
end
end

# Add new namespaces to this constant
#
def self.included(base)
base.send :include,
Elasticsearch::API::Common,
Elasticsearch::API::Actions,
Elasticsearch::API::Cluster,
Elasticsearch::API::Nodes,
Elasticsearch::API::Indices,
Elasticsearch::API::Ingest,
Elasticsearch::API::Snapshot,
Elasticsearch::API::Tasks,
Elasticsearch::API::Cat,
Elasticsearch::API::Remote,
Elasticsearch::API::DanglingIndices,
Elasticsearch::API::Features,
Elasticsearch::API::AsyncSearch,
Elasticsearch::API::Autoscaling,
Elasticsearch::API::CrossClusterReplication,
Elasticsearch::API::DataFrameTransformDeprecated,
Elasticsearch::API::Enrich,
Elasticsearch::API::Eql,
Elasticsearch::API::Fleet,
Elasticsearch::API::Graph,
Elasticsearch::API::IndexLifecycleManagement,
Elasticsearch::API::License,
Elasticsearch::API::Logstash,
Elasticsearch::API::Migration,
Elasticsearch::API::MachineLearning,
Elasticsearch::API::Rollup,
Elasticsearch::API::SearchableSnapshots,
Elasticsearch::API::Security,
Elasticsearch::API::SnapshotLifecycleManagement,
Elasticsearch::API::SQL,
Elasticsearch::API::SSL,
Elasticsearch::API::TextStructure,
Elasticsearch::API::Transform,
Elasticsearch::API::Watcher,
Elasticsearch::API::XPack,
Elasticsearch::API::SearchApplication,
Elasticsearch::API::Synonyms,
Elasticsearch::API::Esql,
Elasticsearch::API::Inference,
Elasticsearch::API::Simulate,
Elasticsearch::API::Connector,
Elasticsearch::API::QueryRules
API_NAMESPACES = [:async_search,
:cat,
:cross_cluster_replication,
:cluster,
:connector,
:dangling_indices,
:enrich,
:eql,
:esql,
:features,
:fleet,
:graph,
:index_lifecycle_management,
:indices,
:inference,
:ingest,
:license,
:logstash,
:migration,
:machine_learning,
:nodes,
:query_rules,
:search_application,
:searchable_snapshots,
:security,
:simulate,
:snapshot_lifecycle_management,
:snapshot,
:sql,
:ssl,
:synonyms,
:tasks,
:text_structure,
:transform,
:watcher,
:xpack].freeze

UPPERCASE_APIS = ['sql', 'ssl'].freeze
API_NAMESPACES.each do |namespace|
name = namespace.to_s
module_name = if UPPERCASE_APIS.include?(name)
name.upcase
elsif name == 'xpack'
'XPack'
else
name.split('_').map(&:capitalize).join
end
class_name = "#{module_name}Client"

klass = Class.new(Object) do
include CommonClient, Object.const_get("Elasticsearch::API::#{module_name}::Actions")
end
Object.const_set(class_name, klass)
define_method(name) do
instance_variable_set("@#{name}", klass.new(self))
end
end

alias ml machine_learning
alias ilm index_lifecycle_management

# The serializer class
#
def self.serializer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,22 @@
# specific language governing permissions and limitations
# under the License.
#
# Auto generated from build hash f284cc16f4d4b4289bc679aa1529bb504190fe80
# @see https://github.com/elastic/elasticsearch/tree/main/rest-api-spec
# Auto generated from commit f284cc16f4d4b4289bc679aa1529bb504190fe80
# @see https://github.com/elastic/elasticsearch-specification
#
module Elasticsearch
module API
module AsyncSearch
module Actions
# Deletes an async search by ID. If the search is still running, the search request will be cancelled. Otherwise, the saved search results are deleted.
# Delete an async search.
# If the asynchronous search is still running, it is cancelled.
# Otherwise, the saved search results are deleted.
# If the Elasticsearch security features are enabled, the deletion of a specific async search is restricted to: the authenticated user that submitted the original search request; users that have the +cancel_task+ cluster privilege.
#
# @option arguments [String] :id The async search ID
# @option arguments [String] :id A unique identifier for the async search. (*Required*)
# @option arguments [Hash] :headers Custom HTTP headers
#
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/async-search.html
# @see https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-async-search-submit
#
def delete(arguments = {})
request_opts = { endpoint: arguments[:endpoint] || 'async_search.delete' }
Expand All @@ -47,7 +50,7 @@ def delete(arguments = {})
_id = arguments.delete(:id)

method = Elasticsearch::API::HTTP_DELETE
path = "_async_search/#{Utils.__listify(_id)}"
path = "_async_search/#{Utils.listify(_id)}"
params = {}

Elasticsearch::API::Response.new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,30 @@
# specific language governing permissions and limitations
# under the License.
#
# Auto generated from build hash f284cc16f4d4b4289bc679aa1529bb504190fe80
# @see https://github.com/elastic/elasticsearch/tree/main/rest-api-spec
# Auto generated from commit f284cc16f4d4b4289bc679aa1529bb504190fe80
# @see https://github.com/elastic/elasticsearch-specification
#
module Elasticsearch
module API
module AsyncSearch
module Actions
# Retrieves the results of a previously submitted async search request given its ID.
# Get async search results.
# Retrieve the results of a previously submitted asynchronous search request.
# If the Elasticsearch security features are enabled, access to the results of a specific async search is restricted to the user or API key that submitted it.
#
# @option arguments [String] :id The async search ID
# @option arguments [Time] :wait_for_completion_timeout Specify the time that the request should block waiting for the final response
# @option arguments [Time] :keep_alive Specify the time interval in which the results (partial or final) for this search will be available
# @option arguments [String] :id A unique identifier for the async search. (*Required*)
# @option arguments [Time] :keep_alive The length of time that the async search should be available in the cluster.
# When not specified, the +keep_alive+ set with the corresponding submit async request will be used.
# Otherwise, it is possible to override the value and extend the validity of the request.
# When this period expires, the search, if still running, is cancelled.
# If the search is completed, its saved results are deleted.
# @option arguments [Boolean] :typed_keys Specify whether aggregation and suggester names should be prefixed by their respective types in the response
# @option arguments [Time] :wait_for_completion_timeout Specifies to wait for the search to be completed up until the provided timeout.
# Final results will be returned if available before the timeout expires, otherwise the currently available results will be returned once the timeout expires.
# By default no timeout is set meaning that the currently available results will be returned without any additional wait.
# @option arguments [Hash] :headers Custom HTTP headers
#
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/async-search.html
# @see https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-async-search-submit
#
def get(arguments = {})
request_opts = { endpoint: arguments[:endpoint] || 'async_search.get' }
Expand All @@ -50,7 +58,7 @@ def get(arguments = {})
_id = arguments.delete(:id)

method = Elasticsearch::API::HTTP_GET
path = "_async_search/#{Utils.__listify(_id)}"
path = "_async_search/#{Utils.listify(_id)}"
params = Utils.process_params(arguments)

Elasticsearch::API::Response.new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,25 @@
# specific language governing permissions and limitations
# under the License.
#
# Auto generated from build hash f284cc16f4d4b4289bc679aa1529bb504190fe80
# @see https://github.com/elastic/elasticsearch/tree/main/rest-api-spec
# Auto generated from commit f284cc16f4d4b4289bc679aa1529bb504190fe80
# @see https://github.com/elastic/elasticsearch-specification
#
module Elasticsearch
module API
module AsyncSearch
module Actions
# Retrieves the status of a previously submitted async search request given its ID.
# Get the async search status.
# Get the status of a previously submitted async search request given its identifier, without retrieving search results.
# If the Elasticsearch security features are enabled, the access to the status of a specific async search is restricted to:
# * The user or API key that submitted the original async search request.
# * Users that have the +monitor+ cluster privilege or greater privileges.
#
# @option arguments [String] :id The async search ID
# @option arguments [Time] :keep_alive Specify the time interval in which the results (partial or final) for this search will be available
# @option arguments [String] :id A unique identifier for the async search. (*Required*)
# @option arguments [Time] :keep_alive The length of time that the async search needs to be available.
# Ongoing async searches and any saved search results are deleted after this period. Server default: 5d.
# @option arguments [Hash] :headers Custom HTTP headers
#
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/async-search.html
# @see https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-async-search-submit
#
def status(arguments = {})
request_opts = { endpoint: arguments[:endpoint] || 'async_search.status' }
Expand All @@ -48,7 +53,7 @@ def status(arguments = {})
_id = arguments.delete(:id)

method = Elasticsearch::API::HTTP_GET
path = "_async_search/status/#{Utils.__listify(_id)}"
path = "_async_search/status/#{Utils.listify(_id)}"
params = Utils.process_params(arguments)

Elasticsearch::API::Response.new(
Expand Down
Loading