Module: ElasticsearchServerless::API::Actions

Included in:
ElasticsearchServerless::API
Defined in:
lib/elasticsearch-serverless/api/get.rb,
lib/elasticsearch-serverless/api/bulk.rb,
lib/elasticsearch-serverless/api/info.rb,
lib/elasticsearch-serverless/api/mget.rb,
lib/elasticsearch-serverless/api/ping.rb,
lib/elasticsearch-serverless/api/count.rb,
lib/elasticsearch-serverless/api/index.rb,
lib/elasticsearch-serverless/api/create.rb,
lib/elasticsearch-serverless/api/delete.rb,
lib/elasticsearch-serverless/api/exists.rb,
lib/elasticsearch-serverless/api/scroll.rb,
lib/elasticsearch-serverless/api/search.rb,
lib/elasticsearch-serverless/api/update.rb,
lib/elasticsearch-serverless/api/explain.rb,
lib/elasticsearch-serverless/api/msearch.rb,
lib/elasticsearch-serverless/api/reindex.rb,
lib/elasticsearch-serverless/api/rank_eval.rb,
lib/elasticsearch-serverless/api/field_caps.rb,
lib/elasticsearch-serverless/api/get_script.rb,
lib/elasticsearch-serverless/api/get_source.rb,
lib/elasticsearch-serverless/api/put_script.rb,
lib/elasticsearch-serverless/api/search_mvt.rb,
lib/elasticsearch-serverless/api/terms_enum.rb,
lib/elasticsearch-serverless/api/termvectors.rb,
lib/elasticsearch-serverless/api/clear_scroll.rb,
lib/elasticsearch-serverless/api/mtermvectors.rb,
lib/elasticsearch-serverless/api/delete_script.rb,
lib/elasticsearch-serverless/api/exists_source.rb,
lib/elasticsearch-serverless/api/delete_by_query.rb,
lib/elasticsearch-serverless/api/search_template.rb,
lib/elasticsearch-serverless/api/update_by_query.rb,
lib/elasticsearch-serverless/api/msearch_template.rb,
lib/elasticsearch-serverless/api/open_point_in_time.rb,
lib/elasticsearch-serverless/api/close_point_in_time.rb,
lib/elasticsearch-serverless/api/render_search_template.rb,
lib/elasticsearch-serverless/api/scripts_painless_execute.rb

Instance Method Summary collapse

Instance Method Details

#bulk(arguments = {}) ⇒ Object

Bulk index or delete documents. Performs multiple indexing or delete operations in a single API call. This reduces overhead and can greatly increase indexing speed.

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :index (String)

    Name of the data stream, index, or index alias to perform bulk actions on.

  • :pipeline (String)

    ID of the pipeline to use to preprocess incoming documents. If the index has a default ingest pipeline specified, then setting the value to _none disables the default ingest pipeline for this request. If a final pipeline is configured it will always run, regardless of the value of this parameter.

  • :refresh (String)

    If true, Elasticsearch refreshes the affected shards to make this operation visible to search, if wait_for then wait for a refresh to make this operation visible to search, if false do nothing with refreshes. Valid values: true, false, wait_for. Server default: false.

  • :routing (String)

    Custom value used to route operations to a specific shard.

  • :_source (Boolean, String, Array<String>)

    true or false to return the _source field or not, or a list of fields to return.

  • :_source_excludes (String, Array<String>)

    A comma-separated list of source fields to exclude from the response.

  • :_source_includes (String, Array<String>)

    A comma-separated list of source fields to include in the response.

  • :timeout (Time)

    Period each action waits for the following operations: automatic index creation, dynamic mapping updates, waiting for active shards. Server default: 1m.

  • :wait_for_active_shards (Integer, String)

    The number of shard copies that must be active before proceeding with the operation. Set to all or any positive integer up to the total number of shards in the index (+number_of_replicas+1+). Server default: 1.

  • :require_alias (Boolean)

    If true, the request’s actions must target an index alias.

  • :headers (Hash)

    Custom HTTP headers

  • :body (String|Array)

    operations. Array of Strings, Header/Data pairs, or the conveniency “combined” format can be passed, refer to ElasticsearchServerless::API::Utils.bulkify documentation.

Raises:

  • (ArgumentError)

See Also:



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/elasticsearch-serverless/api/bulk.rb', line 47

def bulk(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "bulk" }

  defined_params = [:index].inject({}) do |set_variables, variable|
    set_variables[variable] = arguments[variable] if arguments.key?(variable)
    set_variables
  end
  request_opts[:defined_params] = defined_params unless defined_params.empty?

  raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = arguments.delete(:body)

  _index = arguments.delete(:index)

  method = ElasticsearchServerless::API::HTTP_POST
  path   = if _index
             "#{Utils.listify(_index)}/_bulk"
           else
             "_bulk"
           end
  params = Utils.process_params(arguments)

  if body.is_a? Array
    payload = ElasticsearchServerless::API::Utils.bulkify(body)
  else
    payload = body
  end

  headers.merge!("Content-Type" => "application/x-ndjson")
  ElasticsearchServerless::API::Response.new(
    perform_request(method, path, params, payload, headers, request_opts)
  )
end

#clear_scroll(arguments = {}) ⇒ Object

Clear a scrolling search. Clear the search context and results for a scrolling search.

*Deprecation notice*: A scroll id can be quite large and should be specified as part of the body Deprecated since version 7.0.0

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :scroll_id (String, Array)

    Comma-separated list of scroll IDs to clear. To clear all scroll IDs, use _all.

  • :headers (Hash)

    Custom HTTP headers

  • :body (Hash)

    request body

See Also:



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/elasticsearch-serverless/api/clear_scroll.rb', line 39

def clear_scroll(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "clear_scroll" }

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = arguments.delete(:body)

  _scroll_id = arguments.delete(:scroll_id)

  method = ElasticsearchServerless::API::HTTP_DELETE
  path   = "_search/scroll"
  params = Utils.process_params(arguments)

  if Array(arguments[:ignore]).include?(404)
    Utils.rescue_from_not_found {
      ElasticsearchServerless::API::Response.new(
        perform_request(method, path, params, body, headers, request_opts)
      )
    }
  else
    ElasticsearchServerless::API::Response.new(
      perform_request(method, path, params, body, headers, request_opts)
    )
  end
end

#close_point_in_time(arguments = {}) ⇒ Object

Close a point in time. A point in time must be opened explicitly before being used in search requests. The keep_alive parameter tells Elasticsearch how long it should persist. A point in time is automatically closed when the keep_alive period has elapsed. However, keeping points in time has a cost; close them as soon as they are no longer required for search requests.

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :headers (Hash)

    Custom HTTP headers

  • :body (Hash)

    request body

See Also:



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/elasticsearch-serverless/api/close_point_in_time.rb', line 35

def close_point_in_time(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "close_point_in_time" }

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = arguments.delete(:body)

  method = ElasticsearchServerless::API::HTTP_DELETE
  path   = "_pit"
  params = {}

  ElasticsearchServerless::API::Response.new(
    perform_request(method, path, params, body, headers, request_opts)
  )
end

#count(arguments = {}) ⇒ Object

Returns number of documents matching a query.

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :index (String, Array)

    Comma-separated list of data streams, indices, and aliases to search. Supports wildcards (+*+). To search all data streams and indices, omit this parameter or use * or _all.

  • :allow_no_indices (Boolean)

    If false, the request returns an error if any wildcard expression, index alias, or _all value targets only missing or closed indices. This behavior applies even if the request targets other open indices. Server default: true.

  • :analyzer (String)

    Analyzer to use for the query string. This parameter can only be used when the q query string parameter is specified.

  • :analyze_wildcard (Boolean)

    If true, wildcard and prefix queries are analyzed. This parameter can only be used when the q query string parameter is specified.

  • :default_operator (String)

    The default operator for query string query: AND or OR. This parameter can only be used when the q query string parameter is specified.

  • :df (String)

    Field to use as default where no field prefix is given in the query string. This parameter can only be used when the q query string parameter is specified.

  • :expand_wildcards (String, Array<String>)

    Type of index that wildcard patterns can match. If the request can target data streams, this argument determines whether wildcard expressions match hidden data streams. Supports comma-separated values, such as open,hidden. Server default: open.

  • :ignore_throttled (Boolean)

    If true, concrete, expanded or aliased indices are ignored when frozen. Server default: true.

  • :ignore_unavailable (Boolean)

    If false, the request returns an error if it targets a missing or closed index.

  • :lenient (Boolean)

    If true, format-based query failures (such as providing text to a numeric field) in the query string will be ignored.

  • :min_score (Float)

    Sets the minimum _score value that documents must have to be included in the result.

  • :preference (String)

    Specifies the node or shard the operation should be performed on. Random by default.

  • :routing (String)

    Custom value used to route operations to a specific shard.

  • :terminate_after (Integer)

    Maximum number of documents to collect for each shard. If a query reaches this limit, Elasticsearch terminates the query early. Elasticsearch collects documents before sorting.

  • :q (String)

    Query in the Lucene query string syntax.

  • :headers (Hash)

    Custom HTTP headers

  • :body (Hash)

    request body

See Also:



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/elasticsearch-serverless/api/count.rb', line 58

def count(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "count" }

  defined_params = [:index].inject({}) do |set_variables, variable|
    set_variables[variable] = arguments[variable] if arguments.key?(variable)
    set_variables
  end
  request_opts[:defined_params] = defined_params unless defined_params.empty?

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = arguments.delete(:body)

  _index = arguments.delete(:index)

  method = if body
             ElasticsearchServerless::API::HTTP_POST
           else
             ElasticsearchServerless::API::HTTP_GET
           end

  path   = if _index
             "#{Utils.listify(_index)}/_count"
           else
             "_count"
           end
  params = Utils.process_params(arguments)

  ElasticsearchServerless::API::Response.new(
    perform_request(method, path, params, body, headers, request_opts)
  )
end

#create(arguments = {}) ⇒ Object

Index a document. Adds a JSON document to the specified data stream or index and makes it searchable. If the target is an index and the document already exists, the request updates the document and increments its version.

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :id (String)

    Unique identifier for the document. (Required)

  • :index (String)

    Name of the data stream or index to target. If the target doesn’t exist and matches the name or wildcard (+*+) pattern of an index template with a data_stream definition, this request creates the data stream. If the target doesn’t exist and doesn’t match a data stream template, this request creates the index. (Required)

  • :pipeline (String)

    ID of the pipeline to use to preprocess incoming documents. If the index has a default ingest pipeline specified, then setting the value to _none disables the default ingest pipeline for this request. If a final pipeline is configured it will always run, regardless of the value of this parameter.

  • :refresh (String)

    If true, Elasticsearch refreshes the affected shards to make this operation visible to search, if wait_for then wait for a refresh to make this operation visible to search, if false do nothing with refreshes. Valid values: true, false, wait_for. Server default: false.

  • :routing (String)

    Custom value used to route operations to a specific shard.

  • :timeout (Time)

    Period the request waits for the following operations: automatic index creation, dynamic mapping updates, waiting for active shards. Server default: 1m.

  • :version (Integer)

    Explicit version number for concurrency control. The specified version must match the current version of the document for the request to succeed.

  • :version_type (String)

    Specific version type: external, external_gte.

  • :wait_for_active_shards (Integer, String)

    The number of shard copies that must be active before proceeding with the operation. Set to all or any positive integer up to the total number of shards in the index (+number_of_replicas+1+). Server default: 1.

  • :headers (Hash)

    Custom HTTP headers

  • :body (Hash)

    document

See Also:



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/elasticsearch-serverless/api/create.rb', line 49

def create(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "create" }

  defined_params = [:index, :id].inject({}) do |set_variables, variable|
    set_variables[variable] = arguments[variable] if arguments.key?(variable)
    set_variables
  end
  request_opts[:defined_params] = defined_params unless defined_params.empty?

  if arguments[:id]
    index arguments.update op_type: 'create'
  else
    index arguments
  end
end

#delete(arguments = {}) ⇒ Object

Delete a document. Removes a JSON document from the specified index.

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :id (String)

    Unique identifier for the document. (Required)

  • :index (String)

    Name of the target index. (Required)

  • :if_primary_term (Integer)

    Only perform the operation if the document has this primary term.

  • :if_seq_no (Integer)

    Only perform the operation if the document has this sequence number.

  • :refresh (String)

    If true, Elasticsearch refreshes the affected shards to make this operation visible to search, if wait_for then wait for a refresh to make this operation visible to search, if false do nothing with refreshes. Valid values: true, false, wait_for. Server default: false.

  • :routing (String)

    Custom value used to route operations to a specific shard.

  • :timeout (Time)

    Period to wait for active shards. Server default: 1m.

  • :version (Integer)

    Explicit version number for concurrency control. The specified version must match the current version of the document for the request to succeed.

  • :version_type (String)

    Specific version type: external, external_gte.

  • :wait_for_active_shards (Integer, String)

    The number of shard copies that must be active before proceeding with the operation. Set to all or any positive integer up to the total number of shards in the index (+number_of_replicas+1+). Server default: 1.

  • :headers (Hash)

    Custom HTTP headers

Raises:

  • (ArgumentError)

See Also:



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/elasticsearch-serverless/api/delete.rb', line 44

def delete(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "delete" }

  defined_params = [:index, :id].inject({}) do |set_variables, variable|
    set_variables[variable] = arguments[variable] if arguments.key?(variable)
    set_variables
  end
  request_opts[:defined_params] = defined_params unless defined_params.empty?

  raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
  raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = nil

  _id = arguments.delete(:id)

  _index = arguments.delete(:index)

  method = ElasticsearchServerless::API::HTTP_DELETE
  path   = "#{Utils.listify(_index)}/_doc/#{Utils.listify(_id)}"
  params = Utils.process_params(arguments)

  if Array(arguments[:ignore]).include?(404)
    Utils.rescue_from_not_found {
      ElasticsearchServerless::API::Response.new(
        perform_request(method, path, params, body, headers, request_opts)
      )
    }
  else
    ElasticsearchServerless::API::Response.new(
      perform_request(method, path, params, body, headers, request_opts)
    )
  end
end

#delete_by_query(arguments = {}) ⇒ Object

Delete documents. Deletes documents that match the specified query.

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :index (String, Array)

    Comma-separated list of data streams, indices, and aliases to search. Supports wildcards (+*+). To search all data streams or indices, omit this parameter or use * or _all. (Required)

  • :allow_no_indices (Boolean)

    If false, the request returns an error if any wildcard expression, index alias, or _all value targets only missing or closed indices. This behavior applies even if the request targets other open indices. For example, a request targeting foo*,bar* returns an error if an index starts with foo but no index starts with bar. Server default: true.

  • :analyzer (String)

    Analyzer to use for the query string.

  • :analyze_wildcard (Boolean)

    If true, wildcard and prefix queries are analyzed.

  • :conflicts (String)

    What to do if delete by query hits version conflicts: abort or proceed. Server default: abort.

  • :default_operator (String)

    The default operator for query string query: AND or OR. Server default: OR.

  • :df (String)

    Field to use as default where no field prefix is given in the query string.

  • :expand_wildcards (String, Array<String>)

    Type of index that wildcard patterns can match. If the request can target data streams, this argument determines whether wildcard expressions match hidden data streams. Supports comma-separated values, such as open,hidden. Valid values are: all, open, closed, hidden, none. Server default: open.

  • :from (Integer)

    Starting offset (default: 0)

  • :ignore_unavailable (Boolean)

    If false, the request returns an error if it targets a missing or closed index.

  • :lenient (Boolean)

    If true, format-based query failures (such as providing text to a numeric field) in the query string will be ignored.

  • :max_docs (Integer)

    Maximum number of documents to process. Defaults to all documents.

  • :preference (String)

    Specifies the node or shard the operation should be performed on. Random by default.

  • :refresh (Boolean)

    If true, Elasticsearch refreshes all shards involved in the delete by query after the request completes.

  • :request_cache (Boolean)

    If true, the request cache is used for this request. Defaults to the index-level setting.

  • :requests_per_second (Float)

    The throttle for this request in sub-requests per second.

  • :routing (String)

    Custom value used to route operations to a specific shard.

  • :q (String)

    Query in the Lucene query string syntax.

  • :scroll (Time)

    Period to retain the search context for scrolling.

  • :scroll_size (Integer)

    Size of the scroll request that powers the operation. Server default: 1000.

  • :search_timeout (Time)

    Explicit timeout for each search request. Defaults to no timeout.

  • :search_type (String)

    The type of the search operation. Available options: query_then_fetch, dfs_query_then_fetch.

  • :slices (Integer, String)

    The number of slices this task should be divided into. Server default: 1.

  • :sort (Array<String>)

    A comma-separated list of <field>:<direction> pairs.

  • :stats (Array<String>)

    Specific tag of the request for logging and statistical purposes.

  • :terminate_after (Integer)

    Maximum number of documents to collect for each shard. If a query reaches this limit, Elasticsearch terminates the query early. Elasticsearch collects documents before sorting. Use with caution. Elasticsearch applies this parameter to each shard handling the request. When possible, let Elasticsearch perform early termination automatically. Avoid specifying this parameter for requests that target data streams with backing indices across multiple data tiers.

  • :timeout (Time)

    Period each deletion request waits for active shards. Server default: 1m.

  • :version (Boolean)

    If true, returns the document version as part of a hit.

  • :wait_for_active_shards (Integer, String)

    The number of shard copies that must be active before proceeding with the operation. Set to all or any positive integer up to the total number of shards in the index (+number_of_replicas+1+). Server default: 1.

  • :wait_for_completion (Boolean)

    If true, the request blocks until the operation is complete. Server default: true.

  • :headers (Hash)

    Custom HTTP headers

  • :body (Hash)

    request body

Raises:

  • (ArgumentError)

See Also:



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/elasticsearch-serverless/api/delete_by_query.rb', line 80

def delete_by_query(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "delete_by_query" }

  defined_params = [:index].inject({}) do |set_variables, variable|
    set_variables[variable] = arguments[variable] if arguments.key?(variable)
    set_variables
  end
  request_opts[:defined_params] = defined_params unless defined_params.empty?

  raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
  raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = arguments.delete(:body)

  _index = arguments.delete(:index)

  method = ElasticsearchServerless::API::HTTP_POST
  path   = "#{Utils.listify(_index)}/_delete_by_query"
  params = Utils.process_params(arguments)

  ElasticsearchServerless::API::Response.new(
    perform_request(method, path, params, body, headers, request_opts)
  )
end

#delete_script(arguments = {}) ⇒ Object

Delete a script or search template. Deletes a stored script or search template.

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :id (String)

    Identifier for the stored script or search template. (Required)

  • :master_timeout (Time)

    Period to wait for a connection to the master node. If no response is received before the timeout expires, the request fails and returns an error. Server default: 30s.

  • :timeout (Time)

    Period to wait for a response. If no response is received before the timeout expires, the request fails and returns an error. Server default: 30s.

  • :headers (Hash)

    Custom HTTP headers

Raises:

  • (ArgumentError)

See Also:



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/elasticsearch-serverless/api/delete_script.rb', line 36

def delete_script(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "delete_script" }

  defined_params = [:id].inject({}) do |set_variables, variable|
    set_variables[variable] = arguments[variable] if arguments.key?(variable)
    set_variables
  end
  request_opts[:defined_params] = defined_params unless defined_params.empty?

  raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = nil

  _id = arguments.delete(:id)

  method = ElasticsearchServerless::API::HTTP_DELETE
  path   = "_scripts/#{Utils.listify(_id)}"
  params = Utils.process_params(arguments)

  ElasticsearchServerless::API::Response.new(
    perform_request(method, path, params, body, headers, request_opts)
  )
end

#exists(arguments = {}) ⇒ Object Also known as: exists?

Check a document. Checks if a specified document exists.

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :id (String)

    Identifier of the document. (Required)

  • :index (String)

    Comma-separated list of data streams, indices, and aliases. Supports wildcards (+*+). (Required)

  • :preference (String)

    Specifies the node or shard the operation should be performed on. Random by default.

  • :realtime (Boolean)

    If true, the request is real-time as opposed to near-real-time. Server default: true.

  • :refresh (Boolean)

    If true, Elasticsearch refreshes all shards involved in the delete by query after the request completes.

  • :routing (String)

    Target the specified primary shard.

  • :_source (Boolean, String, Array<String>)

    true or false to return the _source field or not, or a list of fields to return.

  • :_source_excludes (String, Array<String>)

    A comma-separated list of source fields to exclude in the response.

  • :_source_includes (String, Array<String>)

    A comma-separated list of source fields to include in the response.

  • :stored_fields (String, Array<String>)

    List of stored fields to return as part of a hit. If no fields are specified, no stored fields are included in the response. If this field is specified, the _source parameter defaults to false.

  • :version (Integer)

    Explicit version number for concurrency control. The specified version must match the current version of the document for the request to succeed.

  • :version_type (String)

    Specific version type: external, external_gte.

  • :headers (Hash)

    Custom HTTP headers

Raises:

  • (ArgumentError)

See Also:



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/elasticsearch-serverless/api/exists.rb', line 48

def exists(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "exists" }

  defined_params = [:index, :id].inject({}) do |set_variables, variable|
    set_variables[variable] = arguments[variable] if arguments.key?(variable)
    set_variables
  end
  request_opts[:defined_params] = defined_params unless defined_params.empty?

  raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
  raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = nil

  _id = arguments.delete(:id)

  _index = arguments.delete(:index)

  method = ElasticsearchServerless::API::HTTP_HEAD
  path   = "#{Utils.listify(_index)}/_doc/#{Utils.listify(_id)}"
  params = Utils.process_params(arguments)

  Utils.rescue_from_not_found do
    perform_request(method, path, params, body, headers, request_opts).status == 200 ? true : false
  end
end

#exists_source(arguments = {}) ⇒ Object Also known as: exists_source?

Check for a document source. Checks if a document’s _source is stored.

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :id (String)

    Identifier of the document. (Required)

  • :index (String)

    Comma-separated list of data streams, indices, and aliases. Supports wildcards (+*+). (Required)

  • :preference (String)

    Specifies the node or shard the operation should be performed on. Random by default.

  • :realtime (Boolean)

    If true, the request is real-time as opposed to near-real-time. Server default: true.

  • :refresh (Boolean)

    If true, Elasticsearch refreshes all shards involved in the delete by query after the request completes.

  • :routing (String)

    Target the specified primary shard.

  • :_source (Boolean, String, Array<String>)

    true or false to return the _source field or not, or a list of fields to return.

  • :_source_excludes (String, Array<String>)

    A comma-separated list of source fields to exclude in the response.

  • :_source_includes (String, Array<String>)

    A comma-separated list of source fields to include in the response.

  • :version (Integer)

    Explicit version number for concurrency control. The specified version must match the current version of the document for the request to succeed.

  • :version_type (String)

    Specific version type: external, external_gte.

  • :headers (Hash)

    Custom HTTP headers

Raises:

  • (ArgumentError)

See Also:



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/elasticsearch-serverless/api/exists_source.rb', line 45

def exists_source(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "exists_source" }

  defined_params = [:index, :id].inject({}) do |set_variables, variable|
    set_variables[variable] = arguments[variable] if arguments.key?(variable)
    set_variables
  end
  request_opts[:defined_params] = defined_params unless defined_params.empty?

  raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
  raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = nil

  _id = arguments.delete(:id)

  _index = arguments.delete(:index)

  method = ElasticsearchServerless::API::HTTP_HEAD
  path   = "#{Utils.listify(_index)}/_source/#{Utils.listify(_id)}"
  params = Utils.process_params(arguments)

  ElasticsearchServerless::API::Response.new(
    perform_request(method, path, params, body, headers, request_opts)
  )
end

#explain(arguments = {}) ⇒ Object

Explain a document match result. Returns information about why a specific document matches, or doesn’t match, a query.

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :id (String)

    Defines the document ID. (Required)

  • :index (String)

    Index names used to limit the request. Only a single index name can be provided to this parameter. (Required)

  • :analyzer (String)

    Analyzer to use for the query string. This parameter can only be used when the q query string parameter is specified.

  • :analyze_wildcard (Boolean)

    If true, wildcard and prefix queries are analyzed.

  • :default_operator (String)

    The default operator for query string query: AND or OR. Server default: OR.

  • :df (String)

    Field to use as default where no field prefix is given in the query string.

  • :lenient (Boolean)

    If true, format-based query failures (such as providing text to a numeric field) in the query string will be ignored.

  • :preference (String)

    Specifies the node or shard the operation should be performed on. Random by default.

  • :routing (String)

    Custom value used to route operations to a specific shard.

  • :_source (Boolean, String, Array<String>)

    True or false to return the _source field or not, or a list of fields to return.

  • :_source_excludes (String, Array<String>)

    A comma-separated list of source fields to exclude from the response.

  • :_source_includes (String, Array<String>)

    A comma-separated list of source fields to include in the response.

  • :stored_fields (String, Array<String>)

    A comma-separated list of stored fields to return in the response.

  • :q (String)

    Query in the Lucene query string syntax.

  • :headers (Hash)

    Custom HTTP headers

  • :body (Hash)

    request body

Raises:

  • (ArgumentError)

See Also:



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/elasticsearch-serverless/api/explain.rb', line 49

def explain(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "explain" }

  defined_params = [:index, :id].inject({}) do |set_variables, variable|
    set_variables[variable] = arguments[variable] if arguments.key?(variable)
    set_variables
  end
  request_opts[:defined_params] = defined_params unless defined_params.empty?

  raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
  raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = arguments.delete(:body)

  _id = arguments.delete(:id)

  _index = arguments.delete(:index)

  method = if body
             ElasticsearchServerless::API::HTTP_POST
           else
             ElasticsearchServerless::API::HTTP_GET
           end

  path   = "#{Utils.listify(_index)}/_explain/#{Utils.listify(_id)}"
  params = Utils.process_params(arguments)

  ElasticsearchServerless::API::Response.new(
    perform_request(method, path, params, body, headers, request_opts)
  )
end

#field_caps(arguments = {}) ⇒ Object

Get the field capabilities. Get information about the capabilities of fields among multiple indices. For data streams, the API returns field capabilities among the stream’s backing indices. It returns runtime fields like any other field. For example, a runtime field with a type of keyword is returned the same as any other field that belongs to the keyword family.

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :index (String, Array)

    Comma-separated list of data streams, indices, and aliases used to limit the request. Supports wildcards (*). To target all data streams and indices, omit this parameter or use * or _all.

  • :allow_no_indices (Boolean)

    If false, the request returns an error if any wildcard expression, index alias, or _all value targets only missing or closed indices. This behavior applies even if the request targets other open indices. For example, a request targeting foo*,bar* returns an error if an index starts with foo but no index starts with bar. Server default: true.

  • :expand_wildcards (String, Array<String>)

    Type of index that wildcard patterns can match. If the request can target data streams, this argument determines whether wildcard expressions match hidden data streams. Supports comma-separated values, such as open,hidden. Server default: open.

  • :fields (String, Array<String>)

    Comma-separated list of fields to retrieve capabilities for. Wildcard (+*+) expressions are supported.

  • :ignore_unavailable (Boolean)

    If true, missing or closed indices are not included in the response.

  • :include_unmapped (Boolean)

    If true, unmapped fields are included in the response.

  • :filters (String)

    An optional set of filters: can include +metadata,-metadata,-nested,-multifield,-parent

  • :types (Array<String>)

    Only return results for fields that have one of the types in the list

  • :include_empty_fields (Boolean)

    If false, empty fields are not included in the response. Server default: true.

  • :headers (Hash)

    Custom HTTP headers

  • :body (Hash)

    request body

See Also:



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/elasticsearch-serverless/api/field_caps.rb', line 46

def field_caps(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "field_caps" }

  defined_params = [:index].inject({}) do |set_variables, variable|
    set_variables[variable] = arguments[variable] if arguments.key?(variable)
    set_variables
  end
  request_opts[:defined_params] = defined_params unless defined_params.empty?

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = arguments.delete(:body)

  _index = arguments.delete(:index)

  method = if body
             ElasticsearchServerless::API::HTTP_POST
           else
             ElasticsearchServerless::API::HTTP_GET
           end

  path   = if _index
             "#{Utils.listify(_index)}/_field_caps"
           else
             "_field_caps"
           end
  params = Utils.process_params(arguments)

  ElasticsearchServerless::API::Response.new(
    perform_request(method, path, params, body, headers, request_opts)
  )
end

#get(arguments = {}) ⇒ Object

Get a document by its ID. Retrieves the document with the specified ID from an index.

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :id (String)

    Unique identifier of the document. (Required)

  • :index (String)

    Name of the index that contains the document. (Required)

  • :force_synthetic_source (Boolean)

    Should this request force synthetic _source? Use this to test if the mapping supports synthetic _source and to get a sense of the worst case performance. Fetches with this enabled will be slower the enabling synthetic source natively in the index.

  • :preference (String)

    Specifies the node or shard the operation should be performed on. Random by default.

  • :realtime (Boolean)

    If true, the request is real-time as opposed to near-real-time. Server default: true.

  • :refresh (Boolean)

    If true, Elasticsearch refreshes the affected shards to make this operation visible to search. If false, do nothing with refreshes.

  • :routing (String)

    Target the specified primary shard.

  • :_source (Boolean, String, Array<String>)

    True or false to return the _source field or not, or a list of fields to return.

  • :_source_excludes (String, Array<String>)

    A comma-separated list of source fields to exclude in the response.

  • :_source_includes (String, Array<String>)

    A comma-separated list of source fields to include in the response.

  • :stored_fields (String, Array<String>)

    List of stored fields to return as part of a hit. If no fields are specified, no stored fields are included in the response. If this field is specified, the _source parameter defaults to false.

  • :version (Integer)

    Explicit version number for concurrency control. The specified version must match the current version of the document for the request to succeed.

  • :version_type (String)

    Specific version type: internal, external, external_gte.

  • :headers (Hash)

    Custom HTTP headers

Raises:

  • (ArgumentError)

See Also:



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/elasticsearch-serverless/api/get.rb', line 48

def get(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "get" }

  defined_params = [:index, :id].inject({}) do |set_variables, variable|
    set_variables[variable] = arguments[variable] if arguments.key?(variable)
    set_variables
  end
  request_opts[:defined_params] = defined_params unless defined_params.empty?

  raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
  raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = nil

  _id = arguments.delete(:id)

  _index = arguments.delete(:index)

  method = ElasticsearchServerless::API::HTTP_GET
  path   = "#{Utils.listify(_index)}/_doc/#{Utils.listify(_id)}"
  params = Utils.process_params(arguments)

  if Array(arguments[:ignore]).include?(404)
    Utils.rescue_from_not_found {
      ElasticsearchServerless::API::Response.new(
        perform_request(method, path, params, body, headers, request_opts)
      )
    }
  else
    ElasticsearchServerless::API::Response.new(
      perform_request(method, path, params, body, headers, request_opts)
    )
  end
end

#get_script(arguments = {}) ⇒ Object

Get a script or search template. Retrieves a stored script or search template.

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :id (String)

    Identifier for the stored script or search template. (Required)

  • :master_timeout (Time)

    Specify timeout for connection to master

  • :headers (Hash)

    Custom HTTP headers

Raises:

  • (ArgumentError)

See Also:



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/elasticsearch-serverless/api/get_script.rb', line 33

def get_script(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "get_script" }

  defined_params = [:id].inject({}) do |set_variables, variable|
    set_variables[variable] = arguments[variable] if arguments.key?(variable)
    set_variables
  end
  request_opts[:defined_params] = defined_params unless defined_params.empty?

  raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = nil

  _id = arguments.delete(:id)

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

  ElasticsearchServerless::API::Response.new(
    perform_request(method, path, params, body, headers, request_opts)
  )
end

#get_source(arguments = {}) ⇒ Object

Get a document’s source. Returns the source of a document.

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :id (String)

    Unique identifier of the document. (Required)

  • :index (String)

    Name of the index that contains the document. (Required)

  • :preference (String)

    Specifies the node or shard the operation should be performed on. Random by default.

  • :realtime (Boolean)

    Boolean) If true, the request is real-time as opposed to near-real-time. Server default: true.

  • :refresh (Boolean)

    If true, Elasticsearch refreshes the affected shards to make this operation visible to search. If false, do nothing with refreshes.

  • :routing (String)

    Target the specified primary shard.

  • :_source (Boolean, String, Array<String>)

    True or false to return the _source field or not, or a list of fields to return.

  • :_source_excludes (String, Array<String>)

    A comma-separated list of source fields to exclude in the response.

  • :_source_includes (String, Array<String>)

    A comma-separated list of source fields to include in the response.

  • :stored_fields (String, Array<String>)
    TODO
  • :version (Integer)

    Explicit version number for concurrency control. The specified version must match the current version of the document for the request to succeed.

  • :version_type (String)

    Specific version type: internal, external, external_gte.

  • :headers (Hash)

    Custom HTTP headers

Raises:

  • (ArgumentError)

See Also:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/elasticsearch-serverless/api/get_source.rb', line 43

def get_source(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "get_source" }

  defined_params = [:index, :id].inject({}) do |set_variables, variable|
    set_variables[variable] = arguments[variable] if arguments.key?(variable)
    set_variables
  end
  request_opts[:defined_params] = defined_params unless defined_params.empty?

  raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
  raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = nil

  _id = arguments.delete(:id)

  _index = arguments.delete(:index)

  method = ElasticsearchServerless::API::HTTP_GET
  path   = "#{Utils.listify(_index)}/_source/#{Utils.listify(_id)}"
  params = Utils.process_params(arguments)

  ElasticsearchServerless::API::Response.new(
    perform_request(method, path, params, body, headers, request_opts)
  )
end

#index(arguments = {}) ⇒ Object

Index a document. Adds a JSON document to the specified data stream or index and makes it searchable. If the target is an index and the document already exists, the request updates the document and increments its version.

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :id (String)

    Unique identifier for the document.

  • :index (String)

    Name of the data stream or index to target. (Required)

  • :if_primary_term (Integer)

    Only perform the operation if the document has this primary term.

  • :if_seq_no (Integer)

    Only perform the operation if the document has this sequence number.

  • :op_type (String)

    Set to create to only index the document if it does not already exist (put if absent). If a document with the specified _id already exists, the indexing operation will fail. Same as using the <index>/_create endpoint. Valid values: index, create. If document id is specified, it defaults to index. Otherwise, it defaults to create.

  • :pipeline (String)

    ID of the pipeline to use to preprocess incoming documents. If the index has a default ingest pipeline specified, then setting the value to _none disables the default ingest pipeline for this request. If a final pipeline is configured it will always run, regardless of the value of this parameter.

  • :refresh (String)

    If true, Elasticsearch refreshes the affected shards to make this operation visible to search, if wait_for then wait for a refresh to make this operation visible to search, if false do nothing with refreshes. Valid values: true, false, wait_for.

  • :routing (String)

    Custom value used to route operations to a specific shard.

  • :timeout (Time)

    Period the request waits for the following operations: automatic index creation, dynamic mapping updates, waiting for active shards. Server default: 1m.

  • :version (Integer)

    Explicit version number for concurrency control. The specified version must match the current version of the document for the request to succeed.

  • :version_type (String)

    Specific version type: external, external_gte.

  • :wait_for_active_shards (Integer, String)

    The number of shard copies that must be active before proceeding with the operation. Set to all or any positive integer up to the total number of shards in the index (+number_of_replicas+1+). Server default: 1.

  • :require_alias (Boolean)

    If true, the destination must be an index alias.

  • :headers (Hash)

    Custom HTTP headers

  • :body (Hash)

    document

Raises:

  • (ArgumentError)

See Also:



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/elasticsearch-serverless/api/index.rb', line 56

def index(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "index" }

  defined_params = [:index, :id].inject({}) do |set_variables, variable|
    set_variables[variable] = arguments[variable] if arguments.key?(variable)
    set_variables
  end
  request_opts[:defined_params] = defined_params unless defined_params.empty?

  raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
  raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = arguments.delete(:body)

  _id = arguments.delete(:id)

  _index = arguments.delete(:index)

  method = _id ? ElasticsearchServerless::API::HTTP_PUT : ElasticsearchServerless::API::HTTP_POST
  path   = if _index && _id
             "#{Utils.listify(_index)}/_doc/#{Utils.listify(_id)}"
           else
             "#{Utils.listify(_index)}/_doc"
           end
  params = Utils.process_params(arguments)

  ElasticsearchServerless::API::Response.new(
    perform_request(method, path, params, body, headers, request_opts)
  )
end

#info(arguments = {}) ⇒ Object

Get cluster info. Returns basic information about the cluster.

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :headers (Hash)

    Custom HTTP headers

See Also:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/elasticsearch-serverless/api/info.rb', line 31

def info(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "info" }

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = nil

  method = ElasticsearchServerless::API::HTTP_GET
  path   = ""
  params = {}

  ElasticsearchServerless::API::Response.new(
    perform_request(method, path, params, body, headers, request_opts)
  )
end

#mget(arguments = {}) ⇒ Object

Get multiple documents. Get multiple JSON documents by ID from one or more indices. If you specify an index in the request URI, you only need to specify the document IDs in the request body. To ensure fast responses, this multi get (mget) API responds with partial results if one or more shards fail.

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :index (String)

    Name of the index to retrieve documents from when ids are specified, or when a document in the docs array does not specify an index.

  • :force_synthetic_source (Boolean)

    Should this request force synthetic _source? Use this to test if the mapping supports synthetic _source and to get a sense of the worst case performance. Fetches with this enabled will be slower the enabling synthetic source natively in the index.

  • :preference (String)

    Specifies the node or shard the operation should be performed on. Random by default.

  • :realtime (Boolean)

    If true, the request is real-time as opposed to near-real-time. Server default: true.

  • :refresh (Boolean)

    If true, the request refreshes relevant shards before retrieving documents.

  • :routing (String)

    Custom value used to route operations to a specific shard.

  • :_source (Boolean, String, Array<String>)

    True or false to return the _source field or not, or a list of fields to return.

  • :_source_excludes (String, Array<String>)

    A comma-separated list of source fields to exclude from the response. You can also use this parameter to exclude fields from the subset specified in _source_includes query parameter.

  • :_source_includes (String, Array<String>)

    A comma-separated list of source fields to include in the response. If this parameter is specified, only these source fields are returned. You can exclude fields from this subset using the _source_excludes query parameter. If the _source parameter is false, this parameter is ignored.

  • :stored_fields (String, Array<String>)

    If true, retrieves the document fields stored in the index rather than the document _source. Server default: false.

  • :headers (Hash)

    Custom HTTP headers

  • :body (Hash)

    request body

Raises:

  • (ArgumentError)

See Also:



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/elasticsearch-serverless/api/mget.rb', line 49

def mget(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "mget" }

  defined_params = [:index].inject({}) do |set_variables, variable|
    set_variables[variable] = arguments[variable] if arguments.key?(variable)
    set_variables
  end
  request_opts[:defined_params] = defined_params unless defined_params.empty?

  raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = arguments.delete(:body)

  _index = arguments.delete(:index)

  method = ElasticsearchServerless::API::HTTP_POST
  path   = if _index
             "#{Utils.listify(_index)}/_mget"
           else
             "_mget"
           end
  params = Utils.process_params(arguments)

  ElasticsearchServerless::API::Response.new(
    perform_request(method, path, params, body, headers, request_opts)
  )
end

#msearch(arguments = {}) ⇒ Object

Run multiple searches. The format of the request is similar to the bulk API format and makes use of the newline delimited JSON (NDJSON) format. The structure is as follows:

header
body
header
body

This structure is specifically optimized to reduce parsing if a specific search ends up redirected to another node. IMPORTANT: The final line of data must end with a newline character \n. Each newline character may be preceded by a carriage return \r. When sending requests to this endpoint the Content-Type header should be set to application/x-ndjson.

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :index (String, Array)

    Comma-separated list of data streams, indices, and index aliases to search.

  • :allow_no_indices (Boolean)

    If false, the request returns an error if any wildcard expression, index alias, or _all value targets only missing or closed indices. This behavior applies even if the request targets other open indices. For example, a request targeting foo*,bar* returns an error if an index starts with foo but no index starts with bar.

  • :ccs_minimize_roundtrips (Boolean)

    If true, network roundtrips between the coordinating node and remote clusters are minimized for cross-cluster search requests. Server default: true.

  • :expand_wildcards (String, Array<String>)

    Type of index that wildcard expressions can match. If the request can target data streams, this argument determines whether wildcard expressions match hidden data streams.

  • :ignore_throttled (Boolean)

    If true, concrete, expanded or aliased indices are ignored when frozen.

  • :ignore_unavailable (Boolean)

    If true, missing or closed indices are not included in the response.

  • :include_named_queries_score (Boolean)

    Indicates whether hit.matched_queries should be rendered as a map that includes the name of the matched query associated with its score (true) or as an array containing the name of the matched queries (false) This functionality reruns each named query on every hit in a search response. Typically, this adds a small overhead to a request. However, using computationally expensive named queries on a large number of hits may add significant overhead.

  • :max_concurrent_searches (Integer)

    Maximum number of concurrent searches the multi search API can execute.

  • :max_concurrent_shard_requests (Integer)

    Maximum number of concurrent shard requests that each sub-search request executes per node. Server default: 5.

  • :pre_filter_shard_size (Integer)

    Defines a threshold that enforces a pre-filter roundtrip to prefilter search shards based on query rewriting if the number of shards the search request expands to exceeds the threshold. This filter roundtrip can limit the number of shards significantly if for instance a shard can not match any documents based on its rewrite method i.e., if date filters are mandatory to match but the shard bounds and the query are disjoint.

  • :rest_total_hits_as_int (Boolean)

    If true, hits.total are returned as an integer in the response. Defaults to false, which returns an object.

  • :routing (String)

    Custom routing value used to route search operations to a specific shard.

  • :search_type (String)

    Indicates whether global term and document frequencies should be used when scoring returned documents.

  • :typed_keys (Boolean)

    Specifies whether aggregation and suggester names should be prefixed by their respective types in the response.

  • :headers (Hash)

    Custom HTTP headers

  • :body (Hash)

    searches

Raises:

  • (ArgumentError)

See Also:



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/elasticsearch-serverless/api/msearch.rb', line 60

def msearch(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "msearch" }

  defined_params = [:index].inject({}) do |set_variables, variable|
    set_variables[variable] = arguments[variable] if arguments.key?(variable)
    set_variables
  end
  request_opts[:defined_params] = defined_params unless defined_params.empty?

  raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = arguments.delete(:body)

  _index = arguments.delete(:index)

  method = ElasticsearchServerless::API::HTTP_POST
  path   = if _index
             "#{Utils.listify(_index)}/_msearch"
           else
             "_msearch"
           end
  params = Utils.process_params(arguments)

  case
  when body.is_a?(Array) && body.any? { |d| d.has_key? :search }
    payload = body.inject([]) do |sum, item|
      meta = item
      data = meta.delete(:search)

      sum << meta
      sum << data
      sum
    end.map { |item| ElasticsearchServerless::API.serializer.dump(item) }
    payload << "" unless payload.empty?
    payload = payload.join("\n")
  when body.is_a?(Array)
    payload = body.map { |d| d.is_a?(String) ? d : ElasticsearchServerless::API.serializer.dump(d) }
    payload << "" unless payload.empty?
    payload = payload.join("\n")
  else
    payload = body
  end

  headers.merge!("Content-Type" => "application/x-ndjson")
  ElasticsearchServerless::API::Response.new(
    perform_request(method, path, params, payload, headers, request_opts)
  )
end

#msearch_template(arguments = {}) ⇒ Object

Run multiple templated searches.

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :index (String, Array)

    Comma-separated list of data streams, indices, and aliases to search. Supports wildcards (+*+). To search all data streams and indices, omit this parameter or use *.

  • :ccs_minimize_roundtrips (Boolean)

    If true, network round-trips are minimized for cross-cluster search requests. Server default: true.

  • :max_concurrent_searches (Integer)

    Maximum number of concurrent searches the API can run.

  • :search_type (String)

    The type of the search operation. Available options: query_then_fetch, dfs_query_then_fetch.

  • :rest_total_hits_as_int (Boolean)

    If true, the response returns hits.total as an integer. If false, it returns hits.total as an object.

  • :typed_keys (Boolean)

    If true, the response prefixes aggregation and suggester names with their respective types.

  • :headers (Hash)

    Custom HTTP headers

  • :body (Hash)

    search_templates

Raises:

  • (ArgumentError)

See Also:



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/elasticsearch-serverless/api/msearch_template.rb', line 41

def msearch_template(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "msearch_template" }

  defined_params = [:index].inject({}) do |set_variables, variable|
    set_variables[variable] = arguments[variable] if arguments.key?(variable)
    set_variables
  end
  request_opts[:defined_params] = defined_params unless defined_params.empty?

  raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = arguments.delete(:body)

  _index = arguments.delete(:index)

  method = ElasticsearchServerless::API::HTTP_POST
  path   = if _index
             "#{Utils.listify(_index)}/_msearch/template"
           else
             "_msearch/template"
           end
  params = Utils.process_params(arguments)

  case
  when body.is_a?(Array)
    payload = body.map { |d| d.is_a?(String) ? d : ElasticsearchServerless::API.serializer.dump(d) }
    payload << "" unless payload.empty?
    payload = payload.join("
")
  else
    payload = body
  end

  headers.merge!("Content-Type" => "application/x-ndjson")
  ElasticsearchServerless::API::Response.new(
    perform_request(method, path, params, payload, headers, request_opts)
  )
end

#mtermvectors(arguments = {}) ⇒ Object

Get multiple term vectors. You can specify existing documents by index and ID or provide artificial documents in the body of the request. You can specify the index in the request body or request URI. The response contains a docs array with all the fetched termvectors. Each element has the structure provided by the termvectors API.

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :index (String)

    Name of the index that contains the documents.

  • :ids (Array<String>)

    A comma-separated list of documents ids. You must define ids as parameter or set “ids” or “docs” in the request body

  • :fields (String, Array<String>)

    Comma-separated list or wildcard expressions of fields to include in the statistics. Used as the default list unless a specific field list is provided in the completion_fields or fielddata_fields parameters.

  • :field_statistics (Boolean)

    If true, the response includes the document count, sum of document frequencies, and sum of total term frequencies. Server default: true.

  • :offsets (Boolean)

    If true, the response includes term offsets. Server default: true.

  • :payloads (Boolean)

    If true, the response includes term payloads. Server default: true.

  • :positions (Boolean)

    If true, the response includes term positions. Server default: true.

  • :preference (String)

    Specifies the node or shard the operation should be performed on. Random by default.

  • :realtime (Boolean)

    If true, the request is real-time as opposed to near-real-time. Server default: true.

  • :routing (String)

    Custom value used to route operations to a specific shard.

  • :term_statistics (Boolean)

    If true, the response includes term frequency and document frequency.

  • :version (Integer)

    If true, returns the document version as part of a hit.

  • :version_type (String)

    Specific version type.

  • :headers (Hash)

    Custom HTTP headers

  • :body (Hash)

    request body

See Also:



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/elasticsearch-serverless/api/mtermvectors.rb', line 50

def mtermvectors(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "mtermvectors" }

  defined_params = [:index].inject({}) do |set_variables, variable|
    set_variables[variable] = arguments[variable] if arguments.key?(variable)
    set_variables
  end
  request_opts[:defined_params] = defined_params unless defined_params.empty?

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = arguments.delete(:body)

  _index = arguments.delete(:index)

  method = if body
             ElasticsearchServerless::API::HTTP_POST
           else
             ElasticsearchServerless::API::HTTP_GET
           end

  path   = if _index
             "#{Utils.listify(_index)}/_mtermvectors"
           else
             "_mtermvectors"
           end
  params = Utils.process_params(arguments)

  ElasticsearchServerless::API::Response.new(
    perform_request(method, path, params, body, headers, request_opts)
  )
end

#open_point_in_time(arguments = {}) ⇒ Object

Open a point in time. A search request by default runs against the most recent visible data of the target indices, which is called point in time. Elasticsearch pit (point in time) is a lightweight view into the state of the data as it existed when initiated. In some cases, it’s preferred to perform multiple search requests using the same point in time. For example, if refreshes happen between search_after requests, then the results of those requests might not be consistent as changes happening between searches are only visible to the more recent point in time. A point in time must be opened explicitly before being used in search requests. The keep_alive parameter tells Elasticsearch how long it should persist.

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :index (String, Array)

    A comma-separated list of index names to open point in time; use _all or empty string to perform the operation on all indices (Required)

  • :keep_alive (Time)

    Extends the time to live of the corresponding point in time. (Required)

  • :ignore_unavailable (Boolean)

    If false, the request returns an error if it targets a missing or closed index.

  • :preference (String)

    Specifies the node or shard the operation should be performed on. Random by default.

  • :routing (String)

    Custom value used to route operations to a specific shard.

  • :expand_wildcards (String, Array<String>)

    Type of index that wildcard patterns can match. If the request can target data streams, this argument determines whether wildcard expressions match hidden data streams. Supports comma-separated values, such as open,hidden. Valid values are: all, open, closed, hidden, none. Server default: open.

  • :allow_partial_search_results (Boolean)

    If false, creating a point in time request when a shard is missing or unavailable will throw an exception. If true, the point in time will contain all the shards that are available at the time of the request.

  • :headers (Hash)

    Custom HTTP headers

  • :body (Hash)

    request body

Raises:

  • (ArgumentError)

See Also:



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/elasticsearch-serverless/api/open_point_in_time.rb', line 50

def open_point_in_time(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "open_point_in_time" }

  defined_params = [:index].inject({}) do |set_variables, variable|
    set_variables[variable] = arguments[variable] if arguments.key?(variable)
    set_variables
  end
  request_opts[:defined_params] = defined_params unless defined_params.empty?

  raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = arguments.delete(:body)

  _index = arguments.delete(:index)

  method = ElasticsearchServerless::API::HTTP_POST
  path   = "#{Utils.listify(_index)}/_pit"
  params = Utils.process_params(arguments)

  ElasticsearchServerless::API::Response.new(
    perform_request(method, path, params, body, headers, request_opts)
  )
end

#ping(arguments = {}) ⇒ Object

Ping the cluster. Returns whether the cluster is running.

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :headers (Hash)

    Custom HTTP headers

See Also:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/elasticsearch-serverless/api/ping.rb', line 31

def ping(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "ping" }

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = nil

  method = ElasticsearchServerless::API::HTTP_HEAD
  path   = ""
  params = {}

  begin
    perform_request(method, path, params, body, headers, request_opts).status == 200 ? true : false
  rescue Exception => e
    if e.class.to_s =~ /NotFound|ConnectionFailed/ || e.message =~ /Not *Found|404|ConnectionFailed/i
      false
    else
      raise e
    end
  end
end

#put_script(arguments = {}) ⇒ Object

Create or update a script or search template. Creates or updates a stored script or search template.

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :id (String)

    Identifier for the stored script or search template. Must be unique within the cluster. (Required)

  • :context (String)

    Context in which the script or search template should run. To prevent errors, the API immediately compiles the script or template in this context.

  • :master_timeout (Time)

    Period to wait for a connection to the master node. If no response is received before the timeout expires, the request fails and returns an error. Server default: 30s.

  • :timeout (Time)

    Period to wait for a response. If no response is received before the timeout expires, the request fails and returns an error. Server default: 30s.

  • :headers (Hash)

    Custom HTTP headers

  • :body (Hash)

    request body

Raises:

  • (ArgumentError)

See Also:



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/elasticsearch-serverless/api/put_script.rb', line 40

def put_script(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "put_script" }

  defined_params = [:id, :context].inject({}) do |set_variables, variable|
    set_variables[variable] = arguments[variable] if arguments.key?(variable)
    set_variables
  end
  request_opts[:defined_params] = defined_params unless defined_params.empty?

  raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
  raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = arguments.delete(:body)

  _id = arguments.delete(:id)

  _context = arguments.delete(:context)

  method = ElasticsearchServerless::API::HTTP_PUT
  path   = if _id && _context
             "_scripts/#{Utils.listify(_id)}/#{Utils.listify(_context)}"
           else
             "_scripts/#{Utils.listify(_id)}"
           end
  params = Utils.process_params(arguments)

  ElasticsearchServerless::API::Response.new(
    perform_request(method, path, params, body, headers, request_opts)
  )
end

#rank_eval(arguments = {}) ⇒ Object

Evaluate ranked search results. Evaluate the quality of ranked search results over a set of typical search queries.

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :index (String, Array)

    Comma-separated list of data streams, indices, and index aliases used to limit the request. Wildcard (+*+) expressions are supported. To target all data streams and indices in a cluster, omit this parameter or use _all or *.

  • :allow_no_indices (Boolean)

    If false, the request returns an error if any wildcard expression, index alias, or _all value targets only missing or closed indices. This behavior applies even if the request targets other open indices. For example, a request targeting foo*,bar* returns an error if an index starts with foo but no index starts with bar. Server default: true.

  • :expand_wildcards (String, Array<String>)

    Whether to expand wildcard expression to concrete indices that are open, closed or both.

  • :ignore_unavailable (Boolean)

    If true, missing or closed indices are not included in the response.

  • :search_type (String)

    Search operation type

  • :headers (Hash)

    Custom HTTP headers

  • :body (Hash)

    request body

Raises:

  • (ArgumentError)

See Also:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/elasticsearch-serverless/api/rank_eval.rb', line 38

def rank_eval(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "rank_eval" }

  defined_params = [:index].inject({}) do |set_variables, variable|
    set_variables[variable] = arguments[variable] if arguments.key?(variable)
    set_variables
  end
  request_opts[:defined_params] = defined_params unless defined_params.empty?

  raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = arguments.delete(:body)

  _index = arguments.delete(:index)

  method = ElasticsearchServerless::API::HTTP_POST
  path   = if _index
             "#{Utils.listify(_index)}/_rank_eval"
           else
             "_rank_eval"
           end
  params = Utils.process_params(arguments)

  ElasticsearchServerless::API::Response.new(
    perform_request(method, path, params, body, headers, request_opts)
  )
end

#reindex(arguments = {}) ⇒ Object

Reindex documents. Copies documents from a source to a destination. The source can be any existing index, alias, or data stream. The destination must differ from the source. For example, you cannot reindex a data stream into itself.

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :refresh (Boolean)

    If true, the request refreshes affected shards to make this operation visible to search.

  • :requests_per_second (Float)

    The throttle for this request in sub-requests per second. Defaults to no throttle. Server default: -1.

  • :scroll (Time)

    Specifies how long a consistent view of the index should be maintained for scrolled search.

  • :slices (Integer, String)

    The number of slices this task should be divided into. Defaults to 1 slice, meaning the task isn’t sliced into subtasks. Server default: 1.

  • :timeout (Time)

    Period each indexing waits for automatic index creation, dynamic mapping updates, and waiting for active shards. Server default: 1m.

  • :wait_for_active_shards (Integer, String)

    The number of shard copies that must be active before proceeding with the operation. Set to all or any positive integer up to the total number of shards in the index (+number_of_replicas+1+). Server default: 1.

  • :wait_for_completion (Boolean)

    If true, the request blocks until the operation is complete. Server default: true.

  • :require_alias (Boolean)

    If true, the destination must be an index alias.

  • :headers (Hash)

    Custom HTTP headers

  • :body (Hash)

    request body

Raises:

  • (ArgumentError)

See Also:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/elasticsearch-serverless/api/reindex.rb', line 43

def reindex(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "reindex" }

  raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = arguments.delete(:body)

  method = ElasticsearchServerless::API::HTTP_POST
  path   = "_reindex"
  params = Utils.process_params(arguments)

  ElasticsearchServerless::API::Response.new(
    perform_request(method, path, params, body, headers, request_opts)
  )
end

#render_search_template(arguments = {}) ⇒ Object

Render a search template. Render a search template as a search request body.

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :id (String)

    ID of the search template to render. If no source is specified, this or the id request body parameter is required.

  • :headers (Hash)

    Custom HTTP headers

  • :body (Hash)

    request body

See Also:



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/elasticsearch-serverless/api/render_search_template.rb', line 34

def render_search_template(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "render_search_template" }

  defined_params = [:id].inject({}) do |set_variables, variable|
    set_variables[variable] = arguments[variable] if arguments.key?(variable)
    set_variables
  end
  request_opts[:defined_params] = defined_params unless defined_params.empty?

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = arguments.delete(:body)

  _id = arguments.delete(:id)

  method = if body
             ElasticsearchServerless::API::HTTP_POST
           else
             ElasticsearchServerless::API::HTTP_GET
           end

  path   = if _id
             "_render/template/#{Utils.listify(_id)}"
           else
             "_render/template"
           end
  params = {}

  ElasticsearchServerless::API::Response.new(
    perform_request(method, path, params, body, headers, request_opts)
  )
end

#scripts_painless_execute(arguments = {}) ⇒ Object

Run a script. Runs a script and returns a result. This functionality is Experimental and may be changed or removed completely in a future release. Elastic will take a best effort approach to fix any issues, but experimental features are not subject to the support SLA of official GA features.

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :headers (Hash)

    Custom HTTP headers

  • :body (Hash)

    request body

See Also:



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/elasticsearch-serverless/api/scripts_painless_execute.rb', line 36

def scripts_painless_execute(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "scripts_painless_execute" }

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = arguments.delete(:body)

  method = if body
             ElasticsearchServerless::API::HTTP_POST
           else
             ElasticsearchServerless::API::HTTP_GET
           end

  path   = "_scripts/painless/_execute"
  params = {}

  ElasticsearchServerless::API::Response.new(
    perform_request(method, path, params, body, headers, request_opts)
  )
end

#scroll(arguments = {}) ⇒ Object

Run a scrolling search. IMPORTANT: The scroll API is no longer recommend for deep pagination. If you need to preserve the index state while paging through more than 10,000 hits, use the search_after parameter with a point in time (PIT). The scroll API gets large sets of results from a single scrolling search request. To get the necessary scroll ID, submit a search API request that includes an argument for the scroll query parameter. The scroll parameter indicates how long Elasticsearch should retain the search context for the request. The search response returns a scroll ID in the _scroll_id response body parameter. You can then use the scroll ID with the scroll API to retrieve the next batch of results for the request. If the Elasticsearch security features are enabled, the access to the results of a specific scroll ID is restricted to the user or API key that submitted the search. You can also use the scroll API to specify a new scroll parameter that extends or shortens the retention period for the search context. IMPORTANT: Results from a scrolling search reflect the state of the index at the time of the initial search request. Subsequent indexing or document changes only affect later search and scroll requests.

*Deprecation notice*: A scroll id can be quite large and should be specified as part of the body Deprecated since version 7.0.0

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :scroll_id (String)

    The scroll ID

  • :scroll (Time)

    Period to retain the search context for scrolling. Server default: 1d.

  • :rest_total_hits_as_int (Boolean)

    If true, the API response’s hit.total property is returned as an integer. If false, the API response’s hit.total property is returned as an object.

  • :headers (Hash)

    Custom HTTP headers

  • :body (Hash)

    request body

See Also:



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/elasticsearch-serverless/api/scroll.rb', line 48

def scroll(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "scroll" }

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = arguments.delete(:body)

  _scroll_id = arguments.delete(:scroll_id)

  method = if body
             ElasticsearchServerless::API::HTTP_POST
           else
             ElasticsearchServerless::API::HTTP_GET
           end

  path   = "_search/scroll"
  params = Utils.process_params(arguments)

  ElasticsearchServerless::API::Response.new(
    perform_request(method, path, params, body, headers, request_opts)
  )
end

#search(arguments = {}) ⇒ Object

Run a search. Get search hits that match the query defined in the request. You can provide search queries using the q query string parameter or the request body. If both are specified, only the query parameter is used.

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :index (String, Array)

    Comma-separated list of data streams, indices, and aliases to search. Supports wildcards (+*+). To search all data streams and indices, omit this parameter or use * or _all.

  • :allow_no_indices (Boolean)

    If false, the request returns an error if any wildcard expression, index alias, or _all value targets only missing or closed indices. This behavior applies even if the request targets other open indices. For example, a request targeting foo*,bar* returns an error if an index starts with foo but no index starts with bar. Server default: true.

  • :allow_partial_search_results (Boolean)

    If true, returns partial results if there are shard request timeouts or shard failures. If false, returns an error with no partial results. Server default: true.

  • :analyzer (String)

    Analyzer to use for the query string. This parameter can only be used when the q query string parameter is specified.

  • :analyze_wildcard (Boolean)

    If true, wildcard and prefix queries are analyzed. This parameter can only be used when the q query string parameter is specified.

  • :batched_reduce_size (Integer)

    The number of shard results that should be reduced at once on the coordinating node. This value should be used as a protection mechanism to reduce the memory overhead per search request if the potential number of shards in the request can be large. Server default: 512.

  • :ccs_minimize_roundtrips (Boolean)

    If true, network round-trips between the coordinating node and the remote clusters are minimized when executing cross-cluster search (CCS) requests. Server default: true.

  • :default_operator (String)

    The default operator for query string query: AND or OR. This parameter can only be used when the q query string parameter is specified. Server default: OR.

  • :df (String)

    Field to use as default where no field prefix is given in the query string. This parameter can only be used when the q query string parameter is specified.

  • :docvalue_fields (String, Array<String>)

    A comma-separated list of fields to return as the docvalue representation for each hit.

  • :expand_wildcards (String, Array<String>)

    Type of index that wildcard patterns can match. If the request can target data streams, this argument determines whether wildcard expressions match hidden data streams. Supports comma-separated values, such as open,hidden.

  • :explain (Boolean)

    If true, returns detailed information about score computation as part of a hit.

  • :ignore_throttled (Boolean)

    If true, concrete, expanded or aliased indices will be ignored when frozen. Server default: true.

  • :ignore_unavailable (Boolean)

    If false, the request returns an error if it targets a missing or closed index.

  • :include_named_queries_score (Boolean)

    Indicates whether hit.matched_queries should be rendered as a map that includes the name of the matched query associated with its score (true) or as an array containing the name of the matched queries (false) This functionality reruns each named query on every hit in a search response. Typically, this adds a small overhead to a request. However, using computationally expensive named queries on a large number of hits may add significant overhead.

  • :lenient (Boolean)

    If true, format-based query failures (such as providing text to a numeric field) in the query string will be ignored. This parameter can only be used when the q query string parameter is specified.

  • :max_concurrent_shard_requests (Integer)

    Defines the number of concurrent shard requests per node this search executes concurrently. This value should be used to limit the impact of the search on the cluster in order to limit the number of concurrent shard requests. Server default: 5.

  • :preference (String)

    Nodes and shards used for the search. By default, Elasticsearch selects from eligible nodes and shards using adaptive replica selection, accounting for allocation awareness. Valid values are: _only_local to run the search only on shards on the local node; _local to, if possible, run the search on shards on the local node, or if not, select shards using the default method; _only_nodes:<node-id>,<node-id> to run the search on only the specified nodes IDs, where, if suitable shards exist on more than one selected node, use shards on those nodes using the default method, or if none of the specified nodes are available, select shards from any available node using the default method; _prefer_nodes:<node-id>,<node-id> to if possible, run the search on the specified nodes IDs, or if not, select shards using the default method; _shards:<shard>,<shard> to run the search only on the specified shards; <custom-string> (any string that does not start with _) to route searches with the same <custom-string> to the same shards in the same order.

  • :pre_filter_shard_size (Integer)

    Defines a threshold that enforces a pre-filter roundtrip to prefilter search shards based on query rewriting if the number of shards the search request expands to exceeds the threshold. This filter roundtrip can limit the number of shards significantly if for instance a shard can not match any documents based on its rewrite method (if date filters are mandatory to match but the shard bounds and the query are disjoint). When unspecified, the pre-filter phase is executed if any of these conditions is met: the request targets more than 128 shards; the request targets one or more read-only index; the primary sort of the query targets an indexed field.

  • :request_cache (Boolean)

    If true, the caching of search results is enabled for requests where size is 0. Defaults to index level settings.

  • :routing (String)

    Custom value used to route operations to a specific shard.

  • :scroll (Time)

    Period to retain the search context for scrolling. See Scroll search results. By default, this value cannot exceed 1d (24 hours). You can change this limit using the search.max_keep_alive cluster-level setting.

  • :search_type (String)

    How distributed term frequencies are calculated for relevance scoring.

  • :stats (Array<String>)

    Specific tag of the request for logging and statistical purposes.

  • :stored_fields (String, Array<String>)

    A comma-separated list of stored fields to return as part of a hit. If no fields are specified, no stored fields are included in the response. If this field is specified, the _source parameter defaults to false. You can pass _source: true to return both source fields and stored fields in the search response.

  • :suggest_field (String)

    Specifies which field to use for suggestions.

  • :suggest_mode (String)

    Specifies the suggest mode. This parameter can only be used when the suggest_field and suggest_text query string parameters are specified. Server default: missing.

  • :suggest_size (Integer)

    Number of suggestions to return. This parameter can only be used when the suggest_field and suggest_text query string parameters are specified.

  • :suggest_text (String)

    The source text for which the suggestions should be returned. This parameter can only be used when the suggest_field and suggest_text query string parameters are specified.

  • :terminate_after (Integer)

    Maximum number of documents to collect for each shard. If a query reaches this limit, Elasticsearch terminates the query early. Elasticsearch collects documents before sorting. Use with caution. Elasticsearch applies this parameter to each shard handling the request. When possible, let Elasticsearch perform early termination automatically. Avoid specifying this parameter for requests that target data streams with backing indices across multiple data tiers. If set to 0 (default), the query does not terminate early. Server default: 0.

  • :timeout (Time)

    Specifies the period of time to wait for a response from each shard. If no response is received before the timeout expires, the request fails and returns an error.

  • :track_total_hits (Boolean, Integer)

    Number of hits matching the query to count accurately. If true, the exact number of hits is returned at the cost of some performance. If false, the response does not include the total number of hits matching the query. Server default: 10000.

  • :track_scores (Boolean)

    If true, calculate and return document scores, even if the scores are not used for sorting.

  • :typed_keys (Boolean)

    If true, aggregation and suggester names are be prefixed by their respective types in the response. Server default: true.

  • :rest_total_hits_as_int (Boolean)

    Indicates whether hits.total should be rendered as an integer or an object in the rest search response.

  • :version (Boolean)

    If true, returns document version as part of a hit.

  • :_source (Boolean, String, Array<String>)

    Indicates which source fields are returned for matching documents. These fields are returned in the hits._source property of the search response. Valid values are: true to return the entire document source; false to not return the document source; <string> to return the source fields that are specified as a comma-separated list (supports wildcard (+*+) patterns). Server default: true.

  • :_source_excludes (String, Array<String>)

    A comma-separated list of source fields to exclude from the response. You can also use this parameter to exclude fields from the subset specified in _source_includes query parameter. If the _source parameter is false, this parameter is ignored.

  • :_source_includes (String, Array<String>)

    A comma-separated list of source fields to include in the response. If this parameter is specified, only these source fields are returned. You can exclude fields from this subset using the _source_excludes query parameter. If the _source parameter is false, this parameter is ignored.

  • :seq_no_primary_term (Boolean)

    If true, returns sequence number and primary term of the last modification of each hit.

  • :q (String)

    Query in the Lucene query string syntax using query parameter search. Query parameter searches do not support the full Elasticsearch Query DSL but are handy for testing.

  • :size (Integer)

    Defines the number of hits to return. By default, you cannot page through more than 10,000 hits using the from and size parameters. To page through more hits, use the search_after parameter. Server default: 10.

  • :from (Integer)

    Starting document offset. Needs to be non-negative. By default, you cannot page through more than 10,000 hits using the from and size parameters. To page through more hits, use the search_after parameter. Server default: 0.

  • :sort (String)

    A comma-separated list of <field>:<direction> pairs.

  • :force_synthetic_source (Boolean)

    Should this request force synthetic _source? Use this to test if the mapping supports synthetic _source and to get a sense of the worst case performance. Fetches with this enabled will be slower the enabling synthetic source natively in the index.

  • :headers (Hash)

    Custom HTTP headers

  • :body (Hash)

    request body

See Also:



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/elasticsearch-serverless/api/search.rb', line 146

def search(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "search" }

  defined_params = [:index].inject({}) do |set_variables, variable|
    set_variables[variable] = arguments[variable] if arguments.key?(variable)
    set_variables
  end
  request_opts[:defined_params] = defined_params unless defined_params.empty?

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = arguments.delete(:body)

  _index = arguments.delete(:index)

  method = if body
             ElasticsearchServerless::API::HTTP_POST
           else
             ElasticsearchServerless::API::HTTP_GET
           end

  path   = if _index
             "#{Utils.listify(_index)}/_search"
           else
             "_search"
           end
  params = Utils.process_params(arguments)

  ElasticsearchServerless::API::Response.new(
    perform_request(method, path, params, body, headers, request_opts)
  )
end

#search_mvt(arguments = {}) ⇒ Object

Search a vector tile. Search a vector tile for geospatial values.

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :index (String, Array)

    Comma-separated list of data streams, indices, or aliases to search (Required)

  • :field (String)

    Field containing geospatial data to return (Required)

  • :zoom (Integer)

    Zoom level for the vector tile to search (Required)

  • :x (Integer)

    X coordinate for the vector tile to search (Required)

  • :y (Integer)

    Y coordinate for the vector tile to search (Required)

  • :exact_bounds (Boolean)

    If false, the meta layer’s feature is the bounding box of the tile. If true, the meta layer’s feature is a bounding box resulting from a geo_bounds aggregation. The aggregation runs on <field> values that intersect the <zoom>/<x>/<y> tile with wrap_longitude set to false. The resulting bounding box may be larger than the vector tile.

  • :extent (Integer)

    Size, in pixels, of a side of the tile. Vector tiles are square with equal sides. Server default: 4096.

  • :grid_agg (String)

    Aggregation used to create a grid for field.

  • :grid_precision (Integer)

    Additional zoom levels available through the aggs layer. For example, if <zoom> is 7 and grid_precision is 8, you can zoom in up to level 15. Accepts 0-8. If 0, results don’t include the aggs layer. Server default: 8.

  • :grid_type (String)

    Determines the geometry type for features in the aggs layer. In the aggs layer, each feature represents a geotile_grid cell. If ‘grid’ each feature is a Polygon of the cells bounding box. If ‘point’ each feature is a Point that is the centroid of the cell. Server default: grid.

  • :size (Integer)

    Maximum number of features to return in the hits layer. Accepts 0-10000. If 0, results don’t include the hits layer. Server default: 10000.

  • :with_labels (Boolean)

    If true, the hits and aggs layers will contain additional point features representing suggested label positions for the original features.

  • :headers (Hash)

    Custom HTTP headers

  • :body (Hash)

    request body

Raises:

  • (ArgumentError)

See Also:



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/elasticsearch-serverless/api/search_mvt.rb', line 55

def search_mvt(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "search_mvt" }

  defined_params = [:index, :field, :zoom, :x, :y].inject({}) do |set_variables, variable|
    set_variables[variable] = arguments[variable] if arguments.key?(variable)
    set_variables
  end
  request_opts[:defined_params] = defined_params unless defined_params.empty?

  raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
  raise ArgumentError, "Required argument 'field' missing" unless arguments[:field]
  raise ArgumentError, "Required argument 'zoom' missing" unless arguments[:zoom]
  raise ArgumentError, "Required argument 'x' missing" unless arguments[:x]
  raise ArgumentError, "Required argument 'y' missing" unless arguments[:y]

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = arguments.delete(:body)

  _index = arguments.delete(:index)

  _field = arguments.delete(:field)

  _zoom = arguments.delete(:zoom)

  _x = arguments.delete(:x)

  _y = arguments.delete(:y)

  method = ElasticsearchServerless::API::HTTP_POST
  path   = "#{Utils.listify(_index)}/_mvt/#{Utils.listify(_field)}/#{Utils.listify(_zoom)}/#{Utils.listify(_x)}/#{Utils.listify(_y)}"
  params = Utils.process_params(arguments)

  ElasticsearchServerless::API::Response.new(
    perform_request(method, path, params, body, headers, request_opts)
  )
end

#search_template(arguments = {}) ⇒ Object

Run a search with a search template.

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :index (String, Array)

    Comma-separated list of data streams, indices, and aliases to search. Supports wildcards (*).

  • :allow_no_indices (Boolean)

    If false, the request returns an error if any wildcard expression, index alias, or _all value targets only missing or closed indices. This behavior applies even if the request targets other open indices. For example, a request targeting foo*,bar* returns an error if an index starts with foo but no index starts with bar. Server default: true.

  • :ccs_minimize_roundtrips (Boolean)

    If true, network round-trips are minimized for cross-cluster search requests.

  • :expand_wildcards (String, Array<String>)

    Type of index that wildcard patterns can match. If the request can target data streams, this argument determines whether wildcard expressions match hidden data streams. Supports comma-separated values, such as open,hidden. Valid values are: all, open, closed, hidden, none.

  • :explain (Boolean)

    If true, the response includes additional details about score computation as part of a hit.

  • :ignore_throttled (Boolean)

    If true, specified concrete, expanded, or aliased indices are not included in the response when throttled. Server default: true.

  • :ignore_unavailable (Boolean)

    If false, the request returns an error if it targets a missing or closed index.

  • :preference (String)

    Specifies the node or shard the operation should be performed on. Random by default.

  • :profile (Boolean)

    If true, the query execution is profiled.

  • :routing (String)

    Custom value used to route operations to a specific shard.

  • :scroll (Time)

    Specifies how long a consistent view of the index should be maintained for scrolled search.

  • :search_type (String)

    The type of the search operation.

  • :rest_total_hits_as_int (Boolean)

    If true, hits.total are rendered as an integer in the response.

  • :typed_keys (Boolean)

    If true, the response prefixes aggregation and suggester names with their respective types.

  • :headers (Hash)

    Custom HTTP headers

  • :body (Hash)

    request body

Raises:

  • (ArgumentError)

See Also:



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/elasticsearch-serverless/api/search_template.rb', line 53

def search_template(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "search_template" }

  defined_params = [:index].inject({}) do |set_variables, variable|
    set_variables[variable] = arguments[variable] if arguments.key?(variable)
    set_variables
  end
  request_opts[:defined_params] = defined_params unless defined_params.empty?

  raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = arguments.delete(:body)

  _index = arguments.delete(:index)

  method = ElasticsearchServerless::API::HTTP_POST
  path   = if _index
             "#{Utils.listify(_index)}/_search/template"
           else
             "_search/template"
           end
  params = Utils.process_params(arguments)

  ElasticsearchServerless::API::Response.new(
    perform_request(method, path, params, body, headers, request_opts)
  )
end

#terms_enum(arguments = {}) ⇒ Object

Get terms in an index. Discover terms that match a partial string in an index. This “terms enum” API is designed for low-latency look-ups used in auto-complete scenarios. If the complete property in the response is false, the returned terms set may be incomplete and should be treated as approximate. This can occur due to a few reasons, such as a request timeout or a node error. NOTE: The terms enum API may return terms from deleted documents. Deleted documents are initially only marked as deleted. It is not until their segments are merged that documents are actually deleted. Until that happens, the terms enum API will return terms from these documents.

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :index (String)

    Comma-separated list of data streams, indices, and index aliases to search. Wildcard (*) expressions are supported. (Required)

  • :headers (Hash)

    Custom HTTP headers

  • :body (Hash)

    request body

Raises:

  • (ArgumentError)

See Also:



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/elasticsearch-serverless/api/terms_enum.rb', line 37

def terms_enum(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "terms_enum" }

  defined_params = [:index].inject({}) do |set_variables, variable|
    set_variables[variable] = arguments[variable] if arguments.key?(variable)
    set_variables
  end
  request_opts[:defined_params] = defined_params unless defined_params.empty?

  raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = arguments.delete(:body)

  _index = arguments.delete(:index)

  method = if body
             ElasticsearchServerless::API::HTTP_POST
           else
             ElasticsearchServerless::API::HTTP_GET
           end

  path   = "#{Utils.listify(_index)}/_terms_enum"
  params = {}

  ElasticsearchServerless::API::Response.new(
    perform_request(method, path, params, body, headers, request_opts)
  )
end

#termvector(arguments = {}) ⇒ Object

Deprecated: Use the plural version, #termvectors



88
89
90
91
# File 'lib/elasticsearch-serverless/api/termvectors.rb', line 88

def termvector(arguments = {})
  warn "[DEPRECATION] `termvector` is deprecated. Please use the plural version, `termvectors` instead."
  termvectors(arguments.merge endpoint: '_termvector')
end

#termvectors(arguments = {}) ⇒ Object

Get term vector information. Get information and statistics about terms in the fields of a particular document.

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :index (String)

    Name of the index that contains the document. (Required)

  • :id (String)

    Unique identifier of the document.

  • :fields (String, Array<String>)

    Comma-separated list or wildcard expressions of fields to include in the statistics. Used as the default list unless a specific field list is provided in the completion_fields or fielddata_fields parameters.

  • :field_statistics (Boolean)

    If true, the response includes the document count, sum of document frequencies, and sum of total term frequencies. Server default: true.

  • :offsets (Boolean)

    If true, the response includes term offsets. Server default: true.

  • :payloads (Boolean)

    If true, the response includes term payloads. Server default: true.

  • :positions (Boolean)

    If true, the response includes term positions. Server default: true.

  • :preference (String)

    Specifies the node or shard the operation should be performed on. Random by default.

  • :realtime (Boolean)

    If true, the request is real-time as opposed to near-real-time. Server default: true.

  • :routing (String)

    Custom value used to route operations to a specific shard.

  • :term_statistics (Boolean)

    If true, the response includes term frequency and document frequency.

  • :version (Integer)

    If true, returns the document version as part of a hit.

  • :version_type (String)

    Specific version type.

  • :headers (Hash)

    Custom HTTP headers

  • :body (Hash)

    request body

Raises:

  • (ArgumentError)

See Also:



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/elasticsearch-serverless/api/termvectors.rb', line 47

def termvectors(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "termvectors" }

  defined_params = [:index, :id].inject({}) do |set_variables, variable|
    set_variables[variable] = arguments[variable] if arguments.key?(variable)
    set_variables
  end
  request_opts[:defined_params] = defined_params unless defined_params.empty?

  raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = arguments.delete(:body)

  _index = arguments.delete(:index)

  _id = arguments.delete(:id)

  method = if body
             ElasticsearchServerless::API::HTTP_POST
           else
             ElasticsearchServerless::API::HTTP_GET
           end

  arguments.delete(:endpoint)
  path = if _index && _id
           "#{Utils.listify(_index)}/_termvectors/#{Utils.listify(_id)}"
         else
           "#{Utils.listify(_index)}/_termvectors"
         end
  params = Utils.process_params(arguments)

  ElasticsearchServerless::API::Response.new(
    perform_request(method, path, params, body, headers, request_opts)
  )
end

#update(arguments = {}) ⇒ Object

Update a document. Updates a document by running a script or passing a partial document.

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :id (String)

    Document ID (Required)

  • :index (String)

    The name of the index (Required)

  • :if_primary_term (Integer)

    Only perform the operation if the document has this primary term.

  • :if_seq_no (Integer)

    Only perform the operation if the document has this sequence number.

  • :lang (String)

    The script language. Server default: painless.

  • :refresh (String)

    If ‘true’, Elasticsearch refreshes the affected shards to make this operation visible to search, if ‘wait_for’ then wait for a refresh to make this operation visible to search, if ‘false’ do nothing with refreshes. Server default: false.

  • :require_alias (Boolean)

    If true, the destination must be an index alias.

  • :retry_on_conflict (Integer)

    Specify how many times should the operation be retried when a conflict occurs. Server default: 0.

  • :routing (String)

    Custom value used to route operations to a specific shard.

  • :timeout (Time)

    Period to wait for dynamic mapping updates and active shards. This guarantees Elasticsearch waits for at least the timeout before failing. The actual wait time could be longer, particularly when multiple waits occur. Server default: 1m.

  • :wait_for_active_shards (Integer, String)

    The number of shard copies that must be active before proceeding with the operations. Set to ‘all’ or any positive integer up to the total number of shards in the index (number_of_replicas+1). Defaults to 1 meaning the primary shard. Server default: 1.

  • :_source (Boolean, String, Array<String>)

    Set to false to disable source retrieval. You can also specify a comma-separated list of the fields you want to retrieve. Server default: true.

  • :_source_excludes (String, Array<String>)

    Specify the source fields you want to exclude.

  • :_source_includes (String, Array<String>)

    Specify the source fields you want to retrieve.

  • :headers (Hash)

    Custom HTTP headers

  • :body (Hash)

    request body

Raises:

  • (ArgumentError)

See Also:



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/elasticsearch-serverless/api/update.rb', line 53

def update(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "update" }

  defined_params = [:index, :id].inject({}) do |set_variables, variable|
    set_variables[variable] = arguments[variable] if arguments.key?(variable)
    set_variables
  end
  request_opts[:defined_params] = defined_params unless defined_params.empty?

  raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
  raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
  raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = arguments.delete(:body)

  _id = arguments.delete(:id)

  _index = arguments.delete(:index)

  method = ElasticsearchServerless::API::HTTP_POST
  path   = "#{Utils.listify(_index)}/_update/#{Utils.listify(_id)}"
  params = Utils.process_params(arguments)

  if Array(arguments[:ignore]).include?(404)
    Utils.rescue_from_not_found {
      ElasticsearchServerless::API::Response.new(
        perform_request(method, path, params, body, headers, request_opts)
      )
    }
  else
    ElasticsearchServerless::API::Response.new(
      perform_request(method, path, params, body, headers, request_opts)
    )
  end
end

#update_by_query(arguments = {}) ⇒ Object

Update documents. Updates documents that match the specified query. If no query is specified, performs an update on every document in the data stream or index without modifying the source, which is useful for picking up mapping changes.

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :index (String, Array)

    Comma-separated list of data streams, indices, and aliases to search. Supports wildcards (+*+). To search all data streams or indices, omit this parameter or use * or _all. (Required)

  • :allow_no_indices (Boolean)

    If false, the request returns an error if any wildcard expression, index alias, or _all value targets only missing or closed indices. This behavior applies even if the request targets other open indices. For example, a request targeting foo*,bar* returns an error if an index starts with foo but no index starts with bar. Server default: true.

  • :analyzer (String)

    Analyzer to use for the query string.

  • :analyze_wildcard (Boolean)

    If true, wildcard and prefix queries are analyzed.

  • :conflicts (String)

    What to do if update by query hits version conflicts: abort or proceed. Server default: abort.

  • :default_operator (String)

    The default operator for query string query: AND or OR. Server default: OR.

  • :df (String)

    Field to use as default where no field prefix is given in the query string.

  • :expand_wildcards (String, Array<String>)

    Type of index that wildcard patterns can match. If the request can target data streams, this argument determines whether wildcard expressions match hidden data streams. Supports comma-separated values, such as open,hidden. Valid values are: all, open, closed, hidden, none.

  • :from (Integer)

    Starting offset (default: 0)

  • :ignore_unavailable (Boolean)

    If false, the request returns an error if it targets a missing or closed index.

  • :lenient (Boolean)

    If true, format-based query failures (such as providing text to a numeric field) in the query string will be ignored.

  • :max_docs (Integer)

    Maximum number of documents to process. Defaults to all documents.

  • :pipeline (String)

    ID of the pipeline to use to preprocess incoming documents. If the index has a default ingest pipeline specified, then setting the value to _none disables the default ingest pipeline for this request. If a final pipeline is configured it will always run, regardless of the value of this parameter.

  • :preference (String)

    Specifies the node or shard the operation should be performed on. Random by default.

  • :q (String)

    Query in the Lucene query string syntax.

  • :refresh (Boolean)

    If true, Elasticsearch refreshes affected shards to make the operation visible to search.

  • :request_cache (Boolean)

    If true, the request cache is used for this request.

  • :requests_per_second (Float)

    The throttle for this request in sub-requests per second. Server default: -1.

  • :routing (String)

    Custom value used to route operations to a specific shard.

  • :scroll (Time)

    Period to retain the search context for scrolling.

  • :scroll_size (Integer)

    Size of the scroll request that powers the operation. Server default: 1000.

  • :search_timeout (Time)

    Explicit timeout for each search request.

  • :search_type (String)

    The type of the search operation. Available options: query_then_fetch, dfs_query_then_fetch.

  • :slices (Integer, String)

    The number of slices this task should be divided into. Server default: 1.

  • :sort (Array<String>)

    A comma-separated list of <field>:<direction> pairs.

  • :stats (Array<String>)

    Specific tag of the request for logging and statistical purposes.

  • :terminate_after (Integer)

    Maximum number of documents to collect for each shard. If a query reaches this limit, Elasticsearch terminates the query early. Elasticsearch collects documents before sorting. Use with caution. Elasticsearch applies this parameter to each shard handling the request. When possible, let Elasticsearch perform early termination automatically. Avoid specifying this parameter for requests that target data streams with backing indices across multiple data tiers.

  • :timeout (Time)

    Period each update request waits for the following operations: dynamic mapping updates, waiting for active shards. Server default: 1m.

  • :version (Boolean)

    If true, returns the document version as part of a hit.

  • :version_type (Boolean)

    Should the document increment the version number (internal) on hit or not (reindex)

  • :wait_for_active_shards (Integer, String)

    The number of shard copies that must be active before proceeding with the operation. Set to all or any positive integer up to the total number of shards in the index (+number_of_replicas+1+). Server default: 1.

  • :wait_for_completion (Boolean)

    If true, the request blocks until the operation is complete. Server default: true.

  • :headers (Hash)

    Custom HTTP headers

  • :body (Hash)

    request body

Raises:

  • (ArgumentError)

See Also:



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/elasticsearch-serverless/api/update_by_query.rb', line 83

def update_by_query(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "update_by_query" }

  defined_params = [:index].inject({}) do |set_variables, variable|
    set_variables[variable] = arguments[variable] if arguments.key?(variable)
    set_variables
  end
  request_opts[:defined_params] = defined_params unless defined_params.empty?

  raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = arguments.delete(:body)

  _index = arguments.delete(:index)

  method = ElasticsearchServerless::API::HTTP_POST
  path   = "#{Utils.listify(_index)}/_update_by_query"
  params = Utils.process_params(arguments)

  ElasticsearchServerless::API::Response.new(
    perform_request(method, path, params, body, headers, request_opts)
  )
end