Method: ElasticsearchServerless::API::Actions#search
- Defined in:
- lib/elasticsearch-serverless/api/search.rb
#search(arguments = {}) ⇒ Object
Returns 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_allvalue 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 withfoobut no index starts withbar. 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
qquery 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 theqquery 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.
-
:min_compatible_shard_node
(String)
—
The minimum version of the node that can handle the request Any handling node with a lower version will fail the request.
-
: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_localto run the search only on shards on the local node;_localto, 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 wheresizeis0. 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 thesearch.max_keep_alivecluster-level setting. -
:search_type
(String)
—
How distributed term frequencies are calculated for relevance scoring.
-
:stats
(Array<String>)
—
Specific
tagof 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
_sourceparameter defaults tofalse. 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_fieldandsuggest_textquery string parameters are specified. Server default: missing. -
:suggest_size
(Integer)
—
Number of suggestions to return. This parameter can only be used when the
suggest_fieldandsuggest_textquery 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_fieldandsuggest_textquery 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. Iffalse, 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.totalshould 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._sourceproperty of the search response. Valid values are:trueto return the entire document source;falseto 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_includesquery parameter. If the_sourceparameter isfalse, 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_excludesquery parameter. If the_sourceparameter isfalse, 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
fromandsizeparameters. To page through more hits, use thesearch_afterparameter. 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
fromandsizeparameters. To page through more hits, use thesearch_afterparameter. 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:
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 179 |
# File 'lib/elasticsearch-serverless/api/search.rb', line 147 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 |