﻿---
title: stack es search cli command
description: Run a search. Behaviour flags: --dry-run — validate all inputs and exit without performing any action 
url: https://www.elastic.co/elastic/docs-builder/docs/4097/reference/elastic-cli/cli/stack/es/search
applies_to:
  - Elastic Cloud Serverless: Preview
  - Elastic Stack: Preview
---

# stack es search cli command
<cli-modifiers>
</cli-modifiers>

```bash
elastic stack es search [options]
```

Run a search.
**Behaviour flags:**
`--dry-run` — validate all inputs and exit without performing any action

## Options

<definitions>
  <definition term="--allow-no-indices">
    A setting that does two separate checks on the index expression.
    If `false`, the request returns an error (1) if any wildcard expression
    (including `_all` and `*`) resolves to zero matching indices or (2) if the
    complete set of resolved indices, aliases or data streams is empty after all
    expressions are evaluated. If `true`, index expressions that resolve to no
    indices are allowed and the request returns an empty result.
  </definition>
  <definition term="--allow-partial-search-results">
    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`.
  </definition>
  <definition term="--analyzer string">
    The analyzer to use for the query string.
    This parameter can be used only when the `q` query string parameter is specified.
  </definition>
  <definition term="--analyze-wildcard">
    If `true`, wildcard and prefix queries are analyzed.
    This parameter can be used only when the `q` query string parameter is specified.
  </definition>
  <definition term="--batched-reduce-size number">
    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.
  </definition>
  <definition term="--ccs-minimize-roundtrips">
    If `true`, network round-trips between the coordinating node and the remote clusters are minimized when running cross-cluster search (CCS) requests.
  </definition>
  <definition term="--default-operator enum">
    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, or
  </definition>
  <definition term="--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.
  </definition>
  <definition term="--docvalue-fields string[]">
    An array of wildcard (`*`) field patterns.
    The request returns doc values for field names matching these patterns in the `hits.fields` property of the response.
    **Repeatable:** pass `--docvalue-fields` multiple times to supply more than one value
  </definition>
  <definition term="--expand-wildcards enum">
    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`.
    **Values:** all, open, closed, hidden, none
    **Repeatable:** pass `--expand-wildcards` multiple times to supply more than one value
  </definition>
  <definition term="--explain">
    If `true`, the request returns detailed information about score computation as part of a hit.
  </definition>
  <definition term="--ignore-throttled">
    If `true`, concrete, expanded or aliased indices will be ignored when frozen.
  </definition>
  <definition term="--ignore-unavailable">
    If `false`, the request returns an error if it targets a concrete (non-wildcarded)
    index, alias, or data stream that is missing, closed, or otherwise unavailable.
    If `true`, unavailable concrete targets are silently ignored.
  </definition>
  <definition term="--include-named-queries-score">
    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.
  </definition>
  <definition term="--lenient">
    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.
  </definition>
  <definition term="--max-concurrent-shard-requests number">
    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.
  </definition>
  <definition term="--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. If suitable shards exist on more than one selected node, use shards on those nodes using the default method. 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. If not, select shards using the default method.
    - `_shards:<shard>,<shard>` to run the search only on the specified shards. You can combine this value with other `preference` values. However, the `_shards` value must come first. For example: `_shards:2,3|_local`.
    - `<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.
  </definition>
  <definition term="--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.
  </definition>
  <definition term="--request-cache">
    If `true`, the caching of search results is enabled for requests where `size` is `0`.
    It defaults to index level settings.
  </definition>
  <definition term="--routing string">
    A custom value that is used to route operations to a specific shard.
    Not allowed when `index.slice.enabled` is `true` for the target index; use `_slice` instead.
    **Repeatable:** pass `--routing` multiple times to supply more than one value
  </definition>
  <definition term="--scroll string">
    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.
  </definition>
  <definition term="--search-type enum">
    Indicates how distributed term frequencies are calculated for relevance scoring.
    **Values:** query_then_fetch, dfs_query_then_fetch
  </definition>
  <definition term="--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.
    **Repeatable:** pass `--stats` multiple times to supply more than one value
  </definition>
  <definition term="--stored-fields 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` property defaults to `false`.
    You can pass `_source: true` to return both source fields and stored fields in the search response.
    **Repeatable:** pass `--stored-fields` multiple times to supply more than one value
  </definition>
  <definition term="--suggest-field string">
    The field to use for suggestions.
  </definition>
  <definition term="--suggest-mode enum">
    The suggest mode.
    This parameter can be used only when the `suggest_field` and `suggest_text` query string parameters are specified.
    **Values:** missing, popular, always
  </definition>
  <definition term="--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.
  </definition>
  <definition term="--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.
  </definition>
  <definition term="--terminate-after number">
    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.
  </definition>
  <definition term="--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.
  </definition>
  <definition term="--track-total-hits number">
    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.
  </definition>
  <definition term="--track-scores">
    If `true`, calculate and return document scores, even if the scores are not used for sorting.
  </definition>
  <definition term="--typed-keys">
    If `true`, aggregation and suggester names are be prefixed by their respective types in the response.
  </definition>
  <definition term="--rest-total-hits-as-int">
    Indicates whether `hits.total` should be rendered as an integer or an object in the rest search response.
  </definition>
  <definition term="--version">
    If `true`, the request returns the document version as part of a hit.
  </definition>
  <definition term="--source string">
    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`.
  </definition>
  <definition term="--source-excludes 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.
    **Repeatable:** pass `--source-excludes` multiple times to supply more than one value
  </definition>
  <definition term="--source-exclude-vectors">
    Whether vectors should be excluded from _source
  </definition>
  <definition term="--source-includes 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.
    **Repeatable:** pass `--source-includes` multiple times to supply more than one value
  </definition>
  <definition term="--seq-no-primary-term">
    If `true`, the request returns sequence number and primary term of the last modification of each hit.
  </definition>
  <definition term="--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.
  </definition>
  <definition term="--size number">
    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.
  </definition>
  <definition term="--from number">
    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.
  </definition>
  <definition term="--sort string">
    A comma-separated list of <field>:<direction> pairs.
    **Repeatable:** pass `--sort` multiple times to supply more than one value
  </definition>
  <definition term="--aggregations string">
    Defines the aggregations that are run as part of the search request.
  </definition>
  <definition term="--collapse string">
    Collapses search results the values of the specified field.
  </definition>
  <definition term="--ext string">
    Configuration of search extensions defined by Elasticsearch plugins.
  </definition>
  <definition term="--highlight string">
    Specifies the highlighter to use for retrieving highlighted snippets from one or more fields in your search results.
  </definition>
  <definition term="--indices-boost string[]">
    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.
    **Repeatable:** pass `--indices-boost` multiple times to supply more than one value
  </definition>
  <definition term="--knn string">
    The approximate kNN search to run.
    **Repeatable:** pass `--knn` multiple times to supply more than one value
  </definition>
  <definition term="--rank string">
    The Reciprocal Rank Fusion (RRF) to use.
  </definition>
  <definition term="--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.
  </definition>
  <definition term="--post-filter string">
    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.
  </definition>
  <definition term="--profile">
    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.
  </definition>
  <definition term="--query string">
    The search definition using the Query DSL.
  </definition>
  <definition term="--rescore string">
    Can be used to improve precision by reordering just the top (for example 100 - 500) documents returned by the `query` and `post_filter` phases.
    **Repeatable:** pass `--rescore` multiple times to supply more than one value
  </definition>
  <definition term="--retriever string">
    A retriever is a specification to describe top documents returned from a search.
    A retriever replaces other elements of the search API that also return top documents such as `query` and `knn`.
  </definition>
  <definition term="--script-fields string">
    Retrieve a script evaluation (based on different fields) for each hit.
  </definition>
  <definition term="--search-after string[]">
    Used to retrieve the next page of hits using a set of sort values from the previous page.
    **Repeatable:** pass `--search-after` multiple times to supply more than one value
  </definition>
  <definition term="--slice string">
    Split a scrolled search into multiple slices that can be consumed independently.
  </definition>
  <definition term="--fields string[]">
    An array of wildcard (`*`) field patterns.
    The request returns values for field names matching these patterns in the `hits.fields` property of the response.
    **Repeatable:** pass `--fields` multiple times to supply more than one value
  </definition>
  <definition term="--suggest string">
    Defines a suggester that provides similar looking terms based on a provided text.
  </definition>
  <definition term="--pit string">
    Limit the search to a point in time (PIT).
    If you provide a PIT, you cannot specify an `<index>` in the request path.
  </definition>
  <definition term="--runtime-mappings string">
    One or more runtime fields in the search request.
    These fields take precedence over mapped fields with the same name.
  </definition>
  <definition term="--index string">
    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`.
    **Repeatable:** pass `--index` multiple times to supply more than one value
  </definition>
  <definition term="--error-trace">
    When set to `true` Elasticsearch will include the full stack trace of errors
    when they occur.
  </definition>
  <definition term="--filter-path string">
    Comma-separated list of filters in dot notation which reduce the response
    returned by Elasticsearch.
    **Repeatable:** pass `--filter-path` multiple times to supply more than one value
  </definition>
  <definition term="--human">
    When set to `true` will return statistics in a format suitable for humans.
    For example `"exists_time": "1h"` for humans and
    `"exists_time_in_millis": 3600000` for computers. When disabled the human
    readable values will be omitted. This makes sense for responses being consumed
    only by machines.
  </definition>
  <definition term="--pretty">
    If set to `true` the returned JSON will be "pretty-formatted". Only use
    this option for debugging only.
  </definition>
  <definition term="--input-file string">
    path to a JSON file to use as command input
  </definition>
  <definition term="--dry-run">
    validate all inputs and exit without performing any action (preview changes without applying them)
  </definition>
</definitions>


## Global Options

<definitions>
  <definition term="--json">
    output as JSON
  </definition>
</definitions>