Type to search.

Run a search

  • POST also GET /{index}/_search
  • POST also GET /_search
Auth

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.

If the Elasticsearch security features are enabled, you must have the read index privilege for the target data stream, index, or alias. For cross-cluster search, refer to the documentation about configuring CCS privileges. To search a point in time (PIT) for an alias, you must have the read index privilege for the alias's data streams or indices.

Search slicing

When paging through a large number of documents, it can be helpful to split the search into multiple slices to consume them independently with the slice and pit properties. By default the splitting is done first on the shards, then locally on each shard. The local splitting partitions the shard into contiguous ranges based on Lucene document IDs.

For instance if the number of shards is equal to 2 and you request 4 slices, the slices 0 and 2 are assigned to the first shard and the slices 1 and 3 are assigned to the second shard.

Important

The same point-in-time ID should be used for all slices. If different PIT IDs are used, slices can overlap and miss documents. This situation can occur because the splitting criterion is based on Lucene document IDs, which are not stable across changes to the index.

Read the reference documentation

Required privileges

Index privileges read

Path parameters

index union string | string[] optional

A comma-separated list of data streams, indices, and aliases to search. It supports wildcards (*). To search all data streams and indices, omit this parameter or use * or _all.

Leave it out to use /_search.

Query parameters

allow_no_indices boolean · default: true

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.

allow_partial_search_results boolean · default: true

If true and there are shard request timeouts or shard failures, the request returns partial results. If false, it returns an error with no partial results.

To override the default behavior, you can set the search.default_allow_partial_results cluster setting to false.

analyzer string

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

analyze_wildcard boolean · default: false

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

batched_reduce_size number · default: 512

The number of shard results that should be reduced at once on the coordinating node. If the potential number of shards in the request can be large, this value should be used as a protection mechanism to reduce the memory overhead per search request.

ccs_minimize_roundtrips boolean · default: true

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

default_operator enum · default: or

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

Values: and AND or OR
df string

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

docvalue_fields union string | string[]

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

expand_wildcards union oneOf · default: open

The 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. It supports comma-separated values such as open,hidden.

Supported values include:

  • all: Match any data stream or index, including hidden ones.
  • open: Match open, non-hidden indices. Also matches any non-hidden data stream.
  • closed: Match closed, non-hidden indices. Also matches any non-hidden data stream. Data streams cannot be closed.
  • hidden: Match hidden data streams and hidden indices. Must be combined with open, closed, or both.
  • none: Wildcard expressions are not accepted.
Values: all open closed hidden none
explain boolean · default: false

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

ignore_throttled boolean · default: true deprecated

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

ignore_unavailable boolean · default: false

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

include_named_queries_score boolean · default: false

If true, the response includes the score contribution from any named queries.

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 · default: false

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

max_concurrent_shard_requests number · default: 5

The number of concurrent shard requests per node that the search runs 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.

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

The 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 number

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. It defaults to index level settings.

routing string

A custom value that is used to route operations to a specific shard.

scroll union oneOf

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

Values: -1 0
search_type enum

Indicates how distributed term frequencies are calculated for relevance scoring.

Supported values include:

  • query_then_fetch: Documents are scored using local term and document frequencies for the shard. This is usually faster but less accurate.
  • dfs_query_then_fetch: Documents are scored using global term and document frequencies across all shards. This is usually slower but more accurate.
Values: query_then_fetch dfs_query_then_fetch
stats string[]

Specific tag of the request for logging and statistical purposes.

stored_fields union string | 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

The field to use for suggestions.

suggest_mode enum · default: missing

The suggest mode. This parameter can be used only when the suggest_field and suggest_text query string parameters are specified.

Supported values include:

  • missing: Only generate suggestions for terms that are not in the shard.
  • popular: Only suggest terms that occur in more docs on the shard than the original term.
  • always: Suggest any matching suggestions based on terms in the suggest text.
Values: missing popular always
suggest_size number

The number of suggestions to return. This parameter can be used only 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 be used only when the suggest_field and suggest_text query string parameters are specified.

terminate_after number · default: 0

The 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.

Important

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.

timeout union oneOf

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. It defaults to no timeout.

Values: -1 0
track_total_hits boolean | number · default: 10000

The 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.

track_scores boolean · default: false

If true, the request calculates and returns document scores, even if the scores are not used for sorting.

typed_keys boolean · default: false

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

rest_total_hits_as_int boolean · default: false

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

version boolean · default: false

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

_source union oneOf · default: true

The source fields that 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 that supports wildcard (*) patterns.
One of: boolean or string
_source_excludes union string | 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 union string | 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, the request returns the sequence number and primary term of the last modification of each hit.

q string

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

Important

This parameter overrides the query parameter in the request body. If both parameters are specified, documents matching the query request body parameter are not returned.

size number · default: 10

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.

from number · default: 0

The starting document offset, which must 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.

sort union string | string[]

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

Request body

aggregations map string to {} Aggregation

Defines the aggregations that are run as part of the search request.

explain boolean · default: false

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

ext map string to object

Configuration of search extensions defined by Elasticsearch plugins.

from number · default: 0

The starting document offset, which must 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.

highlight object

Specifies the highlighter to use for retrieving highlighted snippets from one or more fields in your search results.

Same fields as highlight in inner_hits
track_total_hits boolean | number · default: 10000

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.

indices_boost string to number[]

Boost the _score of documents from specified indices. The boost value is the factor by which scores are multiplied. A boost value greater than 1.0 increases the score. A boost value between 0 and 1.0 decreases the score.

min_score number

The minimum _score for matching documents. Documents with a lower _score are not included in search results and results collected by aggregations.

post_filter {} Query

Use the post_filter parameter to filter search results. The search hits are filtered after the aggregations are calculated. A post filter has no impact on the aggregation results.

profile boolean · default: false

Set to true to return detailed timing information about the execution of individual components in a search request. NOTE: This is a debugging tool and adds significant overhead to search execution.

query {} Query

The search definition using the Query DSL.

script_fields map string to object

Retrieve a script evaluation (based on different fields) for each hit.

search_after union[]

Used to retrieve the next page of hits using a set of sort values from the previous page.

size number · default: 10

The number of hits to return, which must not be 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 property.

sort union oneOf

A comma-separated list of

Same options as sort in inner_hits
_source union oneOf

The source fields that are returned for matching documents. These fields are returned in the hits._source property of the search response. If the stored_fields property is specified, the _source property defaults to false. Otherwise, it defaults to true.

One of:
terminate_after number · default: 0

The 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.

Important

Use with caution. Elasticsearch applies this property to each shard handling the request. When possible, let Elasticsearch perform early termination automatically. Avoid specifying this property for requests that target data streams with backing indices across multiple data tiers.

If set to 0 (default), the query does not terminate early.

timeout string

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. Defaults to no timeout.

track_scores boolean · default: false

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

version boolean · default: false

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

seq_no_primary_term boolean

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

stored_fields union oneOf

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 property defaults to false. You can pass _source: true to return both source fields and stored fields in the search response.

One of: string[] or string
runtime_mappings object

One or more runtime fields in the search request. These fields take precedence over mapped fields with the same name.

stats string[]

The stats groups to associate with the search. Each group maintains a statistics aggregation for its associated searches. You can retrieve these stats using the indices stats API.

Response

application/json
took number required

The number of milliseconds it took Elasticsearch to run the request. This value is calculated by measuring the time elapsed between receipt of a request on the coordinating node and the time at which the coordinating node is ready to send the response. It includes:

  • Communication time between the coordinating node and data nodes
  • Time the request spends in the search thread pool, queued for execution
  • Actual run time

It does not include:

  • Time needed to send the request to Elasticsearch
  • Time needed to serialize the JSON response
  • Time needed to send the response to a client
timed_out boolean required

If true, the request timed out before completion; returned results may be partial or empty.

_shards object required

A count of shards used for the request.

failed number required

The number of shards the operation or search attempted to run on but failed.

successful number required

The number of shards the operation or search succeeded on.

total number required

The number of shards the operation or search will run on overall.

skipped number
hits object required

The returned documents and metadata.

total union oneOf

Total hit count information, present only if track_total_hits wasn't false in the search request.

One of:
relation enum required

Supported values include:

  • eq: Accurate
  • gte: Lower bound, including returned events or sequences
Values: eq gte
value number required
hits object[] required
_index string required
_id string
_score union number | string nullable
fields map string to object
highlight map string to string
inner_hits map string to object
matched_queries union oneOf
One of: string[] or string to number
_ignored string[]
ignored_field_values map string to oneOf
_shard string
_node string
_routing string
_source object
_rank number
_seq_no number
_primary_term number
_version number
sort union[]
max_score union number | string nullable
aggregations map string to {} Aggregation result
fields map string to object
max_score number
num_reduce_phases number
pit_id string
_scroll_id string

The identifier for the search and its search context. You can use this scroll ID with the scroll API to retrieve the next batch of search results for the request. This property is returned only if the scroll query parameter is specified in the request.

suggest map string to oneOf
terminated_early boolean