Module: ElasticsearchServerless::API::AsyncSearch::Actions

Defined in:
lib/elasticsearch-serverless/api/async_search/get.rb,
lib/elasticsearch-serverless/api/async_search/delete.rb,
lib/elasticsearch-serverless/api/async_search/status.rb,
lib/elasticsearch-serverless/api/async_search/submit.rb

Instance Method Summary collapse

Instance Method Details

#delete(arguments = {}) ⇒ Object

Delete an async search. If the asynchronous search is still running, it is cancelled. Otherwise, the saved search results are deleted. If the Elasticsearch security features are enabled, the deletion of a specific async search is restricted to: the authenticated user that submitted the original search request; users that have the cancel_task cluster privilege.

Parameters:

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

    a customizable set of options

Options Hash (arguments):

  • :id (String)

    A unique identifier for the async search. (Required)

  • :headers (Hash)

    Custom HTTP headers

Raises:

  • (ArgumentError)

See Also:



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
# File 'lib/elasticsearch-serverless/api/async_search/delete.rb', line 35

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

  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   = "_async_search/#{Utils.listify(_id)}"
  params = {}

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

#get(arguments = {}) ⇒ Object

Get async search results. Retrieve the results of a previously submitted asynchronous search request. If the Elasticsearch security features are enabled, access to the results of a specific async search is restricted to the user or API key that submitted it.

Parameters:

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

    a customizable set of options

Options Hash (arguments):

  • :id (String)

    A unique identifier for the async search. (Required)

  • :keep_alive (Time)

    Specifies how long the async search should be available in the cluster. When not specified, the keep_alive set with the corresponding submit async request will be used. Otherwise, it is possible to override the value and extend the validity of the request. When this period expires, the search, if still running, is cancelled. If the search is completed, its saved results are deleted.

  • :typed_keys (Boolean)

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

  • :wait_for_completion_timeout (Time)

    Specifies to wait for the search to be completed up until the provided timeout. Final results will be returned if available before the timeout expires, otherwise the currently available results will be returned once the timeout expires. By default no timeout is set meaning that the currently available results will be returned without any additional wait.

  • :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
# File 'lib/elasticsearch-serverless/api/async_search/get.rb', line 43

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

  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   = "_async_search/#{Utils.listify(_id)}"
  params = Utils.process_params(arguments)

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

#status(arguments = {}) ⇒ Object

Get the async search status. Get the status of a previously submitted async search request given its identifier, without retrieving search results. If the Elasticsearch security features are enabled, use of this API is restricted to the monitoring_user role.

Parameters:

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

    a customizable set of options

Options Hash (arguments):

  • :id (String)

    A unique identifier for the async search. (Required)

  • :keep_alive (Time)

    Specifies how long the async search needs to be available. Ongoing async searches and any saved search results are deleted after this period. Server default: 5d.

  • :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/async_search/status.rb', line 36

def status(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "async_search.status" }

  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   = "_async_search/status/#{Utils.listify(_id)}"
  params = Utils.process_params(arguments)

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

#submit(arguments = {}) ⇒ Object

Run an async search. When the primary sort of the results is an indexed field, shards get sorted based on minimum and maximum value that they hold for that field. Partial results become available following the sort criteria that was requested. Warning: Asynchronous search does not support scroll or search requests that include only the suggest section. By default, Elasticsearch does not allow you to store an async search response larger than 10Mb and an attempt to do this results in an error. The maximum allowed size for a stored async search response can be set by changing the search.max_async_search_response_size cluster level setting.

Parameters:

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

    a customizable set of options

Options Hash (arguments):

  • :index (String, Array)

    A comma-separated list of index names to search; use _all or empty string to perform the operation on all indices

  • :wait_for_completion_timeout (Time)

    Blocks and waits until the search is completed up to a certain timeout. When the async search completes within the timeout, the response won’t include the ID as the results are not stored in the cluster. Server default: 1s.

  • :keep_on_completion (Boolean)

    If true, results are stored for later retrieval when the search completes within the wait_for_completion_timeout.

  • :keep_alive (Time)

    Specifies how long the async search needs to be available. Ongoing async searches and any saved search results are deleted after this period. Server default: 5d.

  • :allow_no_indices (Boolean)

    Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes _all string or when no indices have been specified)

  • :allow_partial_search_results (Boolean)

    Indicate if an error should be returned if there is a partial search failure or timeout

  • :analyzer (String)

    The analyzer to use for the query string

  • :analyze_wildcard (Boolean)

    Specify whether wildcard and prefix queries should be analyzed (default: false)

  • :batched_reduce_size (Integer)

    Affects how often partial results become available, which happens whenever shard results are reduced. A partial reduction is performed every time the coordinating node has received a certain number of new shard responses (5 by default). Server default: 5.

  • :ccs_minimize_roundtrips (Boolean)

    The default value is the only supported value.

  • :default_operator (String)

    The default operator for query string query (AND or OR)

  • :df (String)

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

  • :docvalue_fields (String, Array<String>)

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

  • :expand_wildcards (String, Array<String>)

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

  • :explain (Boolean)

    Specify whether to return detailed information about score computation as part of a hit

  • :ignore_throttled (Boolean)

    Whether specified concrete, expanded or aliased indices should be ignored when throttled

  • :ignore_unavailable (Boolean)

    Whether specified concrete indices should be ignored when unavailable (missing or closed)

  • :lenient (Boolean)

    Specify whether format-based query failures (such as providing text to a numeric field) should be ignored

  • :max_concurrent_shard_requests (Integer)

    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

  • :preference (String)

    Specify the node or shard the operation should be performed on (default: random)

  • :pre_filter_shard_size (Integer)

    The default value cannot be changed, which enforces the execution of a pre-filter roundtrip to retrieve statistics from each shard so that the ones that surely don’t hold any document matching the query get skipped. Server default: 1.

  • :request_cache (Boolean)

    Specify if request cache should be used for this request or not, defaults to true Server default: true.

  • :routing (String)

    A comma-separated list of specific routing values

  • :search_type (String)

    Search operation type

  • :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

  • :suggest_field (String)

    Specifies which field to use for suggestions.

  • :suggest_mode (String)

    Specify suggest mode

  • :suggest_size (Integer)

    How many suggestions to return in response

  • :suggest_text (String)

    The source text for which the suggestions should be returned.

  • :terminate_after (Integer)

    The maximum number of documents to collect for each shard, upon reaching which the query execution will terminate early.

  • :timeout (Time)

    Explicit operation timeout

  • :track_total_hits (Boolean, Integer)

    Indicate if the number of documents that match the query should be tracked. A number can also be specified, to accurately track the total hit count up to the number.

  • :track_scores (Boolean)

    Whether to calculate and return scores even if they are not used for sorting

  • :typed_keys (Boolean)

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

  • :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)

    Specify whether to return document version as part of a hit

  • :_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 list of fields to exclude from the returned _source field

  • :_source_includes (String, Array<String>)

    A list of fields to extract and return from the _source field

  • :seq_no_primary_term (Boolean)

    Specify whether to return sequence number and primary term of the last modification of each hit

  • :q (String)

    Query in the Lucene query string syntax

  • :size (Integer)

    Number of hits to return (default: 10)

  • :from (Integer)

    Starting offset (default: 0)

  • :sort (String)

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

  • :headers (Hash)

    Custom HTTP headers

  • :body (Hash)

    request body

See Also:



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
111
# File 'lib/elasticsearch-serverless/api/async_search/submit.rb', line 84

def submit(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "async_search.submit" }

  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 = ElasticsearchServerless::API::HTTP_POST
  path   = if _index
             "#{Utils.listify(_index)}/_async_search"
           else
             "_async_search"
           end
  params = Utils.process_params(arguments)

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