CINXE.COM

Query string query | Elasticsearch Guide [8.16] | Elastic

<!DOCTYPE html> <html lang="en-us"> <head> <meta charset="UTF-8"> <title>Query string query | Elasticsearch Guide [8.16] | Elastic</title> <meta class="elastic" name="content" content="Query string query | Elasticsearch Guide [8.16]"> <link rel="home" href="index.html" title="Elasticsearch Guide [8.16]"/> <link rel="up" href="full-text-queries.html" title="Full text queries"/> <link rel="prev" href="query-dsl-multi-match-query.html" title="Multi-match query"/> <link rel="next" href="query-dsl-simple-query-string-query.html" title="Simple query string query"/> <meta class="elastic" name="product_version" content="8.16"/> <meta class="elastic" name="product_name" content="Elasticsearch"/> <meta class="elastic" name="website_area" content="documentation"/> <meta name="DC.type" content="Learn/Docs/Elasticsearch/Reference/8.16"/> <meta name="DC.subject" content="Elasticsearch"/> <meta name="DC.identifier" content="8.16"/> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <script src="https://cdn.optimizely.com/js/18132920325.js"></script> <link rel="apple-touch-icon" sizes="57x57" href="/apple-icon-57x57.png"> <link rel="apple-touch-icon" sizes="60x60" href="/apple-icon-60x60.png"> <link rel="apple-touch-icon" sizes="72x72" href="/apple-icon-72x72.png"> <link rel="apple-touch-icon" sizes="76x76" href="/apple-icon-76x76.png"> <link rel="apple-touch-icon" sizes="114x114" href="/apple-icon-114x114.png"> <link rel="apple-touch-icon" sizes="120x120" href="/apple-icon-120x120.png"> <link rel="apple-touch-icon" sizes="144x144" href="/apple-icon-144x144.png"> <link rel="apple-touch-icon" sizes="152x152" href="/apple-icon-152x152.png"> <link rel="apple-touch-icon" sizes="180x180" href="/apple-icon-180x180.png"> <link rel="icon" type="image/png" href="/favicon-32x32.png" sizes="32x32"> <link rel="icon" type="image/png" href="/android-chrome-192x192.png" sizes="192x192"> <link rel="icon" type="image/png" href="/favicon-96x96.png" sizes="96x96"> <link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16"> <link rel="manifest" href="/manifest.json"> <meta name="apple-mobile-web-app-title" content="Elastic"> <meta name="application-name" content="Elastic"> <meta name="msapplication-TileColor" content="#ffffff"> <meta name="msapplication-TileImage" content="/mstile-144x144.png"> <meta name="theme-color" content="#ffffff"> <meta name="naver-site-verification" content="936882c1853b701b3cef3721758d80535413dbfd" /> <meta name="yandex-verification" content="d8a47e95d0972434" /> <meta name="localized" content="true" /> <meta name="st:robots" content="follow,index" /> <meta property="og:image" content="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt280217a63b82a734/6202d3378b1f312528798412/elastic-logo.svg" /> <meta property="og:image:width" content="500" /> <meta property="og:image:height" content="172" /> <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"> <link rel="icon" href="/favicon.ico" type="image/x-icon"> <link rel="apple-touch-icon-precomposed" sizes="64x64" href="/favicon_64x64_16bit.png"> <link rel="apple-touch-icon-precomposed" sizes="32x32" href="/favicon_32x32.png"> <link rel="apple-touch-icon-precomposed" sizes="16x16" href="/favicon_16x16.png"> <!-- Give IE8 a fighting chance --> <!--[if lt IE 9]> <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> <![endif]--> <link rel="stylesheet" type="text/css" href="/guide/static/styles-v1.css" /> </head> <!--© 2015-2025 Elasticsearch B.V. --> <!-- All Elastic documentation is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. --> <!-- http://creativecommons.org/licenses/by-nc-nd/4.0/ --> <body> <!-- Google Tag Manager --> <script>dataLayer = [];</script><noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-58RLH5" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript> <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= '//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-58RLH5');</script> <!-- End Google Tag Manager --> <!-- Global site tag (gtag.js) - Google Analytics --> <script async src="https://www.googletagmanager.com/gtag/js?id=UA-12395217-16"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-12395217-16'); </script> <!-- Google Tag Manager for GA4 --> <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','GTM-KNJMG2M');</script> <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-KNJMG2M" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript> <!-- End Google Tag Manager for GA4--> <div id='elastic-nav' style="display:none;"></div> <script src='https://www.elastic.co/elastic-nav.js'></script> <div class="main-container"> <section id="content" > <div class="content-wrapper"> <section id="guide" lang="en"> <div class="container-fluid"> <div class="row pb-3"> <div class="col-12 order-2 col-md-4 order-md-1 col-lg-3 h-almost-full-md sticky-top-md" id="left_col"> <!-- The TOC is appended here --> </div> <div class="col-12 order-1 col-md-8 order-md-2 col-lg-7 order-lg-2 guide-section" id="middle_col"> <!-- start body --> <div class="navheader"> <span class="prev"> <a href="query-dsl-multi-match-query.html">« Multi-match query</a> </span> <span class="next"> <a href="query-dsl-simple-query-string-query.html">Simple query string query »</a> </span> </div> <div class="book" lang="en"> <div class="titlepage"> <div class="breadcrumbs"> <span class="breadcrumb-link"><a href="/guide/">Elastic Docs</a></span> <span class="chevron-right">›</span><span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [8.16]</a></span> <span class="chevron-right">›</span><span class="breadcrumb-link"><a href="query-dsl.html">Query DSL</a></span> <span class="chevron-right">›</span><span class="breadcrumb-link"><a href="full-text-queries.html">Full text queries</a></span> </div> <div> <div><h1 class="title"><a id="id-1"></a>Query string query</h1><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/elasticsearch/edit/8.16/docs/reference/query-dsl/query-string-query.asciidoc">edit</a></div> </div> <!--EXTRA--> </div> <div id="content"> <div class="section"> <div class="titlepage"><div><div> <div class="position-relative"><h2 class="title"><a id="query-dsl-query-string-query"></a>Query string query</h2><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/elasticsearch/edit/8.16/docs/reference/query-dsl/query-string-query.asciidoc">edit</a></div> </div></div></div> <div class="tip admon"> <div class="icon"></div> <div class="admon_content"> <p>This page contains information about the <code class="literal">query_string</code> query type. For information about running a search query in Elasticsearch, see <a class="xref" href="search-your-data.html" title="The search API"><em>The search API</em></a>.</p> </div> </div> <p>Returns documents based on a provided query string, using a parser with a strict syntax.</p> <p>This query uses a <a class="xref" href="query-dsl-query-string-query.html#query-string-syntax" title="Query string syntax">syntax</a> to parse and split the provided query string based on operators, such as <code class="literal">AND</code> or <code class="literal">NOT</code>. The query then <a class="xref" href="analysis.html" title="Text analysis">analyzes</a> each split text independently before returning matching documents.</p> <p>You can use the <code class="literal">query_string</code> query to create a complex search that includes wildcard characters, searches across multiple fields, and more. While versatile, the query is strict and returns an error if the query string includes any invalid syntax.</p> <div class="warning admon"> <div class="icon"></div> <div class="admon_content"> <p>Because it returns an error for any invalid syntax, we don&#8217;t recommend using the <code class="literal">query_string</code> query for search boxes.</p> <p>If you don&#8217;t need to support a query syntax, consider using the <a class="xref" href="query-dsl-match-query.html" title="Match query"><code class="literal">match</code></a> query. If you need the features of a query syntax, use the <a class="xref" href="query-dsl-simple-query-string-query.html" title="Simple query string query"><code class="literal">simple_query_string</code></a> query, which is less strict.</p> </div> </div> <div class="section"> <div class="titlepage"><div><div> <div class="position-relative"><h3 class="title"><a id="query-string-query-ex-request"></a>Example request</h3><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/elasticsearch/edit/8.16/docs/reference/query-dsl/query-string-query.asciidoc">edit</a></div> </div></div></div> <p>When running the following search, the <code class="literal">query_string</code> query splits <code class="literal">(new york city) OR (big apple)</code> into two parts: <code class="literal">new york city</code> and <code class="literal">big apple</code>. The <code class="literal">content</code> field&#8217;s analyzer then independently converts each part into tokens before returning matching documents. Because the query syntax does not use whitespace as an operator, <code class="literal">new york city</code> is passed as-is to the analyzer.</p> <div class="pre_wrapper lang-python alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-python alternative">resp = client.search( query={ "query_string": { "query": "(new york city) OR (big apple)", "default_field": "content" } }, ) print(resp)</pre> </div> <div class="pre_wrapper lang-ruby alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-ruby alternative">response = client.search( body: { query: { query_string: { query: '(new york city) OR (big apple)', default_field: 'content' } } } ) puts response</pre> </div> <div class="pre_wrapper lang-go alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-go alternative">res, err := es.Search( es.Search.WithBody(strings.NewReader(`{ "query": { "query_string": { "query": "(new york city) OR (big apple)", "default_field": "content" } } }`)), es.Search.WithPretty(), ) fmt.Println(res, err)</pre> </div> <div class="pre_wrapper lang-js alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-js alternative">const response = await client.search({ query: { query_string: { query: "(new york city) OR (big apple)", default_field: "content", }, }, }); console.log(response);</pre> </div> <a id="2a9747bcfaf1f9491ebd410b3fcb6798"></a> <div class="pre_wrapper lang-console default has-python has-ruby has-go has-js"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-console default has-python has-ruby has-go has-js">GET /_search { "query": { "query_string": { "query": "(new york city) OR (big apple)", "default_field": "content" } } }</pre> </div> <div class="console_widget has-python has-ruby has-go has-js" data-snippet="snippets/1472.console"></div> </div> <div class="section"> <div class="titlepage"><div><div> <div class="position-relative"><h3 class="title"><a id="query-string-top-level-params"></a>Top-level parameters for <code class="literal">query_string</code></h3><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/elasticsearch/edit/8.16/docs/reference/query-dsl/query-string-query.asciidoc">edit</a></div> </div></div></div> <div class="variablelist"> <dl class="variablelist"> <dt> <span class="term"> <code class="literal">query</code> </span> </dt> <dd> (Required, string) Query string you wish to parse and use for search. See <a class="xref" href="query-dsl-query-string-query.html#query-string-syntax" title="Query string syntax">Query string syntax</a>. </dd> <dt> <span class="term"> <code class="literal">default_field</code> </span> </dt> <dd> <p>(Optional, string) Default field to search if no field is provided in the query string. Supports wildcards (<code class="literal">*</code>).</p> <p>Defaults to the <a class="xref" href="index-modules.html#index-query-default-field"><code class="literal">index.query.default_field</code></a> index setting, which has a default value of <code class="literal">*</code>. The <code class="literal">*</code> value extracts all fields that are eligible for term queries and filters the metadata fields. All extracted fields are then combined to build a query if no <code class="literal">prefix</code> is specified.</p> <p>Searching across all eligible fields does not include <a class="xref" href="nested.html" title="Nested field type">nested documents</a>. Use a <a class="xref" href="query-dsl-nested-query.html" title="Nested query"><code class="literal">nested</code> query</a> to search those documents.</p> <div id="WARNING" class="exampleblock"> <div class="content"> <p>For mappings with a large number of fields, searching across all eligible fields could be expensive.</p> <p>There is a limit on the number of fields times terms that can be queried at once. It is defined by the <code class="literal">indices.query.bool.max_clause_count</code> <a class="xref" href="search-settings.html" title="Search settings">search setting</a>.</p> </div> </div> </dd> <dt> <span class="term"> <code class="literal">allow_leading_wildcard</code> </span> </dt> <dd> (Optional, Boolean) If <code class="literal">true</code>, the wildcard characters <code class="literal">*</code> and <code class="literal">?</code> are allowed as the first character of the query string. Defaults to <code class="literal">true</code>. </dd> <dt> <span class="term"> <code class="literal">analyze_wildcard</code> </span> </dt> <dd> (Optional, Boolean) If <code class="literal">true</code>, the query attempts to analyze wildcard terms in the query string. Defaults to <code class="literal">false</code>. </dd> <dt> <span class="term"> <code class="literal">analyzer</code> </span> </dt> <dd> (Optional, string) <a class="xref" href="analysis.html" title="Text analysis">Analyzer</a> used to convert text in the query string into tokens. Defaults to the <a class="xref" href="specify-analyzer.html#specify-index-time-analyzer" title="How Elasticsearch determines the index analyzer">index-time analyzer</a> mapped for the <code class="literal">default_field</code>. If no analyzer is mapped, the index&#8217;s default analyzer is used. </dd> <dt> <span class="term"> <code class="literal">auto_generate_synonyms_phrase_query</code> </span> </dt> <dd> (Optional, Boolean) If <code class="literal">true</code>, <a class="xref" href="query-dsl-match-query-phrase.html" title="Match phrase query">match phrase</a> queries are automatically created for multi-term synonyms. Defaults to <code class="literal">true</code>. See <a class="xref" href="query-dsl-query-string-query.html#query-string-synonyms" title="Synonyms and the query_string query">Synonyms and the <code class="literal">query_string</code> query</a> for an example. </dd> <dt> <span class="term"> <code class="literal">boost</code> </span> </dt> <dd> <p>(Optional, float) Floating point number used to decrease or increase the <a class="xref" href="query-filter-context.html#relevance-scores" title="Relevance scores">relevance scores</a> of the query. Defaults to <code class="literal">1.0</code>.</p> <p>Boost values are relative to the default value of <code class="literal">1.0</code>. A boost value between <code class="literal">0</code> and <code class="literal">1.0</code> decreases the relevance score. A value greater than <code class="literal">1.0</code> increases the relevance score.</p> </dd> <dt> <span class="term"> <code class="literal">default_operator</code> </span> </dt> <dd> <p>(Optional, string) Default boolean logic used to interpret text in the query string if no operators are specified. Valid values are:</p> <div class="variablelist"> <dl class="variablelist"> <dt> <span class="term"> <code class="literal">OR</code> (Default) </span> </dt> <dd> For example, a query string of <code class="literal">capital of Hungary</code> is interpreted as <code class="literal">capital OR of OR Hungary</code>. </dd> <dt> <span class="term"> <code class="literal">AND</code> </span> </dt> <dd> For example, a query string of <code class="literal">capital of Hungary</code> is interpreted as <code class="literal">capital AND of AND Hungary</code>. </dd> </dl> </div> </dd> <dt> <span class="term"> <code class="literal">enable_position_increments</code> </span> </dt> <dd> (Optional, Boolean) If <code class="literal">true</code>, enable position increments in queries constructed from a <code class="literal">query_string</code> search. Defaults to <code class="literal">true</code>. </dd> <dt> <span class="term"> <code class="literal">fields</code> </span> </dt> <dd> <p> (Optional, array of strings) Array of fields to search. Supports wildcards (<code class="literal">*</code>). </p> <p>You can use this parameter query to search across multiple fields. See <a class="xref" href="query-dsl-query-string-query.html#query-string-multi-field" title="Search multiple fields">Search multiple fields</a>.</p> </dd> <dt> <span class="term"> <code class="literal">fuzziness</code> </span> </dt> <dd> (Optional, string) Maximum edit distance allowed for fuzzy matching. For fuzzy syntax, see <a class="xref" href="query-dsl-query-string-query.html#query-string-fuzziness" title="Fuzziness">Fuzziness</a>. </dd> <dt> <span class="term"> <code class="literal">fuzzy_max_expansions</code> </span> </dt> <dd> (Optional, integer) Maximum number of terms to which the query expands for fuzzy matching. Defaults to <code class="literal">50</code>. </dd> <dt> <span class="term"> <code class="literal">fuzzy_prefix_length</code> </span> </dt> <dd> (Optional, integer) Number of beginning characters left unchanged for fuzzy matching. Defaults to <code class="literal">0</code>. </dd> <dt> <span class="term"> <code class="literal">fuzzy_transpositions</code> </span> </dt> <dd> (Optional, Boolean) If <code class="literal">true</code>, edits for fuzzy matching include transpositions of two adjacent characters (ab → ba). Defaults to <code class="literal">true</code>. </dd> <dt> <span class="term"> <code class="literal">lenient</code> </span> </dt> <dd> (Optional, Boolean) If <code class="literal">true</code>, format-based errors, such as providing a text value for a <a class="xref" href="number.html" title="Numeric field types">numeric</a> field, are ignored. Defaults to <code class="literal">false</code>. </dd> <dt> <span class="term"> <code class="literal">max_determinized_states</code> </span> </dt> <dd> <p>(Optional, integer) Maximum number of <a href="https://en.wikipedia.org/wiki/Deterministic_finite_automaton" class="ulink" target="_top">automaton states</a> required for the query. Default is <code class="literal">10000</code>.</p> <p>Elasticsearch uses <a href="https://lucene.apache.org/core/" class="ulink" target="_top">Apache Lucene</a> internally to parse regular expressions. Lucene converts each regular expression to a finite automaton containing a number of determinized states.</p> <p>You can use this parameter to prevent that conversion from unintentionally consuming too many resources. You may need to increase this limit to run complex regular expressions.</p> </dd> <dt> <span class="term"> <code class="literal">minimum_should_match</code> </span> </dt> <dd> (Optional, string) Minimum number of clauses that must match for a document to be returned. See the <a class="xref" href="query-dsl-minimum-should-match.html" title="minimum_should_match parameter"><code class="literal">minimum_should_match</code> parameter</a> for valid values and more information. See <a class="xref" href="query-dsl-query-string-query.html#query-string-min-should-match" title="How minimum_should_match works">How <code class="literal">minimum_should_match</code> works</a> for an example. </dd> <dt> <span class="term"> <code class="literal">quote_analyzer</code> </span> </dt> <dd> <p>(Optional, string) <a class="xref" href="analysis.html" title="Text analysis">Analyzer</a> used to convert quoted text in the query string into tokens. Defaults to the <a class="xref" href="analyzer.html#search-quote-analyzer" title="search_quote_analyzer"><code class="literal">search_quote_analyzer</code></a> mapped for the <code class="literal">default_field</code>.</p> <p>For quoted text, this parameter overrides the analyzer specified in the <code class="literal">analyzer</code> parameter.</p> </dd> <dt> <span class="term"> <code class="literal">phrase_slop</code> </span> </dt> <dd> (Optional, integer) Maximum number of positions allowed between matching tokens for phrases. Defaults to <code class="literal">0</code>. If <code class="literal">0</code>, exact phrase matches are required. Transposed terms have a slop of <code class="literal">2</code>. </dd> <dt> <span class="term"> <code class="literal">quote_field_suffix</code> </span> </dt> <dd> <p>(Optional, string) Suffix appended to quoted text in the query string.</p> <p>You can use this suffix to use a different analysis method for exact matches. See <a class="xref" href="mixing-exact-search-with-stemming.html" title="Mixing exact search with stemming">Mixing exact search with stemming</a>.</p> </dd> <dt> <span class="term"> <code class="literal">rewrite</code> </span> </dt> <dd> (Optional, string) Method used to rewrite the query. For valid values and more information, see the <a class="xref" href="query-dsl-multi-term-rewrite.html" title="rewrite parameter"><code class="literal">rewrite</code> parameter</a>. </dd> <dt> <span class="term"> <code class="literal">time_zone</code> </span> </dt> <dd> <p>(Optional, string) <a href="https://en.wikipedia.org/wiki/List_of_UTC_time_offsets" class="ulink" target="_top">Coordinated Universal Time (UTC) offset</a> or <a href="https://en.wikipedia.org/wiki/List_of_tz_database_time_zones" class="ulink" target="_top">IANA time zone</a> used to convert <code class="literal">date</code> values in the query string to UTC.</p> <p>Valid values are ISO 8601 UTC offsets, such as <code class="literal">+01:00</code> or -<code class="literal">08:00</code>, and IANA time zone IDs, such as <code class="literal">America/Los_Angeles</code>.</p> <div class="note admon"> <div class="icon"></div> <div class="admon_content"> <p>The <code class="literal">time_zone</code> parameter does <span class="strong strong"><strong>not</strong></span> affect the <a class="xref" href="common-options.html#date-math" title="Date Math">date math</a> value of <code class="literal">now</code>. <code class="literal">now</code> is always the current system time in UTC. However, the <code class="literal">time_zone</code> parameter does convert dates calculated using <code class="literal">now</code> and <a class="xref" href="common-options.html#date-math" title="Date Math">date math rounding</a>. For example, the <code class="literal">time_zone</code> parameter will convert a value of <code class="literal">now/d</code>.</p> </div> </div> </dd> </dl> </div> </div> <div class="section"> <div class="titlepage"><div><div> <div class="position-relative"><h3 class="title"><a id="query-string-query-notes"></a>Notes</h3><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/elasticsearch/edit/8.16/docs/reference/query-dsl/query-string-query.asciidoc">edit</a></div> </div></div></div> <div class="section"> <div class="titlepage"><div><div> <div class="position-relative"><h4 class="title"><a id="query-string-syntax"></a>Query string syntax</h4><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/elasticsearch/edit/8.16/docs/reference/query-dsl/query-string-syntax.asciidoc">edit</a></div> </div></div></div> <p>The query string &#8220;mini-language&#8221; is used by the <a class="xref" href="query-dsl-query-string-query.html" title="Query string query">Query string</a> and by the <code class="literal">q</code> query string parameter in the <a class="xref" href="search-search.html" title="Search API"><code class="literal">search</code> API</a>.</p> <p>The query string is parsed into a series of <em>terms</em> and <em>operators</em>. A term can be a single word&#8201;&#8212;&#8201;<code class="literal">quick</code> or <code class="literal">brown</code>&#8201;&#8212;&#8201;or a phrase, surrounded by double quotes&#8201;&#8212;&#8201;<code class="literal">"quick brown"</code>&#8201;&#8212;&#8201;which searches for all the words in the phrase, in the same order.</p> <p>Operators allow you to customize the search&#8201;&#8212;&#8201;the available options are explained below.</p> <div class="section"> <div class="titlepage"><div><div> <div class="position-relative"><h5 class="title"><a id="_field_names"></a>Field names</h5><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/elasticsearch/edit/8.16/docs/reference/query-dsl/query-string-syntax.asciidoc">edit</a></div> </div></div></div> <p>You can specify fields to search in the query syntax:</p> <div class="ulist itemizedlist"> <ul class="itemizedlist"> <li class="listitem"> <p>where the <code class="literal">status</code> field contains <code class="literal">active</code></p> <pre class="literallayout">status:active</pre> </li> <li class="listitem"> <p>where the <code class="literal">title</code> field contains <code class="literal">quick</code> or <code class="literal">brown</code></p> <pre class="literallayout">title:(quick OR brown)</pre> </li> <li class="listitem"> <p>where the <code class="literal">author</code> field contains the exact phrase <code class="literal">"john smith"</code></p> <pre class="literallayout">author:"John Smith"</pre> </li> <li class="listitem"> <p>where the <code class="literal">first name</code> field contains <code class="literal">Alice</code> (note how we need to escape the space with a backslash)</p> <pre class="literallayout">first\ name:Alice</pre> </li> <li class="listitem"> <p>where any of the fields <code class="literal">book.title</code>, <code class="literal">book.content</code> or <code class="literal">book.date</code> contains <code class="literal">quick</code> or <code class="literal">brown</code> (note how we need to escape the <code class="literal">*</code> with a backslash):</p> <pre class="literallayout">book.\*:(quick OR brown)</pre> </li> <li class="listitem"> <p>where the field <code class="literal">title</code> has any non-null value:</p> <pre class="literallayout">_exists_:title</pre> </li> </ul> </div> </div> <div class="section"> <div class="titlepage"><div><div> <div class="position-relative"><h5 class="title"><a id="query-string-wildcard"></a>Wildcards</h5><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/elasticsearch/edit/8.16/docs/reference/query-dsl/query-string-syntax.asciidoc">edit</a></div> </div></div></div> <p>Wildcard searches can be run on individual terms, using <code class="literal">?</code> to replace a single character, and <code class="literal">*</code> to replace zero or more characters:</p> <pre class="literallayout">qu?ck bro*</pre> <p>Be aware that wildcard queries can use an enormous amount of memory and perform very badly&#8201;&#8212;&#8201;just think how many terms need to be queried to match the query string <code class="literal">"a* b* c*"</code>.</p> <div class="warning admon"> <div class="icon"></div> <div class="admon_content"> <p>Pure wildcards <code class="literal">\*</code> are rewritten to <a class="xref" href="query-dsl-exists-query.html" title="Exists query"><code class="literal">exists</code></a> queries for efficiency. As a consequence, the wildcard <code class="literal">"field:*"</code> would match documents with an empty value like the following:</p> <pre class="screen">{ "field": "" }</pre> <p>... and would <span class="strong strong"><strong>not</strong></span> match if the field is missing or set with an explicit null value like the following:</p> <pre class="screen">{ "field": null }</pre> </div> </div> <div class="warning admon"> <div class="icon"></div> <div class="admon_content"> <p>Allowing a wildcard at the beginning of a word (eg <code class="literal">"*ing"</code>) is particularly heavy, because all terms in the index need to be examined, just in case they match. Leading wildcards can be disabled by setting <code class="literal">allow_leading_wildcard</code> to <code class="literal">false</code>.</p> </div> </div> <p>Only parts of the analysis chain that operate at the character level are applied. So for instance, if the analyzer performs both lowercasing and stemming, only the lowercasing will be applied: it would be wrong to perform stemming on a word that is missing some of its letters.</p> <p>By setting <code class="literal">analyze_wildcard</code> to true, queries that end with a <code class="literal">*</code> will be analyzed and a boolean query will be built out of the different tokens, by ensuring exact matches on the first N-1 tokens, and prefix match on the last token.</p> </div> <div class="section"> <div class="titlepage"><div><div> <div class="position-relative"><h5 class="title"><a id="_regular_expressions"></a>Regular expressions</h5><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/elasticsearch/edit/8.16/docs/reference/query-dsl/query-string-syntax.asciidoc">edit</a></div> </div></div></div> <p>Regular expression patterns can be embedded in the query string by wrapping them in forward-slashes (<code class="literal">"/"</code>):</p> <pre class="literallayout">name:/joh?n(ath[oa]n)/</pre> <p>The supported regular expression syntax is explained in <a class="xref" href="regexp-syntax.html" title="Regular expression syntax"><em>Regular expression syntax</em></a>.</p> <div class="warning admon"> <div class="icon"></div> <div class="admon_content"> <p>The <code class="literal">allow_leading_wildcard</code> parameter does not have any control over regular expressions. A query string such as the following would force Elasticsearch to visit every term in the index:</p> <pre class="literallayout">/.*n/</pre> <p>Use with caution!</p> </div> </div> </div> <div class="section"> <div class="titlepage"><div><div> <div class="position-relative"><h5 class="title"><a id="query-string-fuzziness"></a>Fuzziness</h5><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/elasticsearch/edit/8.16/docs/reference/query-dsl/query-string-syntax.asciidoc">edit</a></div> </div></div></div> <p>You can run <a class="xref" href="query-dsl-fuzzy-query.html" title="Fuzzy query"><code class="literal">fuzzy</code> queries</a> using the <code class="literal">~</code> operator:</p> <pre class="literallayout">quikc~ brwn~ foks~</pre> <p>For these queries, the query string is <a class="xref" href="analysis-normalizers.html" title="Normalizers">normalized</a>. If present, only certain filters from the analyzer are applied. For a list of applicable filters, see <a class="xref" href="analysis-normalizers.html" title="Normalizers"><em>Normalizers</em></a>.</p> <p>The query uses the <a href="https://en.wikipedia.org/wiki/Damerau-Levenshtein_distance" class="ulink" target="_top">Damerau-Levenshtein distance</a> to find all terms with a maximum of two changes, where a change is the insertion, deletion or substitution of a single character, or transposition of two adjacent characters.</p> <p>The default <em>edit distance</em> is <code class="literal">2</code>, but an edit distance of <code class="literal">1</code> should be sufficient to catch 80% of all human misspellings. It can be specified as:</p> <pre class="literallayout">quikc~1</pre> <div class="warning admon"> <div class="icon"></div> <div class="admon_content"> <p class="admon_title">Avoid mixing fuzziness with wildcards<a id="avoid-widlcards-fuzzy-searches"></a></p> <p>Mixing <a class="xref" href="common-options.html#fuzziness" title="Fuzziness">fuzzy</a> and <a class="xref" href="query-dsl-query-string-query.html#query-string-wildcard" title="Wildcards">wildcard</a> operators is <em>not</em> supported. When mixed, one of the operators is not applied. For example, you can search for <code class="literal">app~1</code> (fuzzy) or <code class="literal">app*</code> (wildcard), but searches for <code class="literal">app*~1</code> do not apply the fuzzy operator (<code class="literal">~1</code>).</p> </div> </div> </div> <div class="section"> <div class="titlepage"><div><div> <div class="position-relative"><h5 class="title"><a id="_proximity_searches"></a>Proximity searches</h5><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/elasticsearch/edit/8.16/docs/reference/query-dsl/query-string-syntax.asciidoc">edit</a></div> </div></div></div> <p>While a phrase query (eg <code class="literal">"john smith"</code>) expects all of the terms in exactly the same order, a proximity query allows the specified words to be further apart or in a different order. In the same way that fuzzy queries can specify a maximum edit distance for characters in a word, a proximity search allows us to specify a maximum edit distance of words in a phrase:</p> <pre class="literallayout">"fox quick"~5</pre> <p>The closer the text in a field is to the original order specified in the query string, the more relevant that document is considered to be. When compared to the above example query, the phrase <code class="literal">"quick fox"</code> would be considered more relevant than <code class="literal">"quick brown fox"</code>.</p> </div> <div class="section"> <div class="titlepage"><div><div> <div class="position-relative"><h5 class="title"><a id="_ranges"></a>Ranges</h5><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/elasticsearch/edit/8.16/docs/reference/query-dsl/query-string-syntax.asciidoc">edit</a></div> </div></div></div> <p>Ranges can be specified for date, numeric or string fields. Inclusive ranges are specified with square brackets <code class="literal">[min TO max]</code> and exclusive ranges with curly brackets <code class="literal">{min TO max}</code>.</p> <div class="ulist itemizedlist"> <ul class="itemizedlist"> <li class="listitem"> <p>All days in 2012:</p> <pre class="literallayout">date:[2012-01-01 TO 2012-12-31]</pre> </li> <li class="listitem"> <p>Numbers 1..5</p> <pre class="literallayout">count:[1 TO 5]</pre> </li> <li class="listitem"> <p>Tags between <code class="literal">alpha</code> and <code class="literal">omega</code>, excluding <code class="literal">alpha</code> and <code class="literal">omega</code>:</p> <pre class="literallayout">tag:{alpha TO omega}</pre> </li> <li class="listitem"> <p>Numbers from 10 upwards</p> <pre class="literallayout">count:[10 TO *]</pre> </li> <li class="listitem"> <p>Dates before 2012</p> <pre class="literallayout">date:{* TO 2012-01-01}</pre> </li> </ul> </div> <p>Curly and square brackets can be combined:</p> <div class="ulist itemizedlist"> <ul class="itemizedlist"> <li class="listitem"> <p>Numbers from 1 up to but not including 5</p> <pre class="literallayout">count:[1 TO 5}</pre> </li> </ul> </div> <p>Ranges with one side unbounded can use the following syntax:</p> <pre class="literallayout">age:&gt;10 age:&gt;=10 age:&lt;10 age:&lt;=10</pre> <div class="note admon"> <div class="icon"></div> <div class="admon_content"> <p>To combine an upper and lower bound with the simplified syntax, you would need to join two clauses with an <code class="literal">AND</code> operator:</p> <pre class="literallayout">age:(&gt;=10 AND &lt;20) age:(+&gt;=10 +&lt;20)</pre> </div> </div> <p>The parsing of ranges in query strings can be complex and error prone. It is much more reliable to use an explicit <a class="xref" href="query-dsl-range-query.html" title="Range query"><code class="literal">range</code> query</a>.</p> </div> <div class="section"> <div class="titlepage"><div><div> <div class="position-relative"><h5 class="title"><a id="_boosting"></a>Boosting</h5><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/elasticsearch/edit/8.16/docs/reference/query-dsl/query-string-syntax.asciidoc">edit</a></div> </div></div></div> <p>Use the <em>boost</em> operator <code class="literal">^</code> to make one term more relevant than another. For instance, if we want to find all documents about foxes, but we are especially interested in quick foxes:</p> <pre class="literallayout">quick^2 fox</pre> <p>The default <code class="literal">boost</code> value is 1, but can be any positive floating point number. Boosts between 0 and 1 reduce relevance.</p> <p>Boosts can also be applied to phrases or to groups:</p> <pre class="literallayout">"john smith"^2 (foo bar)^4</pre> </div> <div class="section"> <div class="titlepage"><div><div> <div class="position-relative"><h5 class="title"><a id="_boolean_operators"></a>Boolean operators</h5><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/elasticsearch/edit/8.16/docs/reference/query-dsl/query-string-syntax.asciidoc">edit</a></div> </div></div></div> <p>By default, all terms are optional, as long as one term matches. A search for <code class="literal">foo bar baz</code> will find any document that contains one or more of <code class="literal">foo</code> or <code class="literal">bar</code> or <code class="literal">baz</code>. We have already discussed the <code class="literal">default_operator</code> above which allows you to force all terms to be required, but there are also <em>boolean operators</em> which can be used in the query string itself to provide more control.</p> <p>The preferred operators are <code class="literal">+</code> (this term <span class="strong strong"><strong>must</strong></span> be present) and <code class="literal">-</code> (this term <span class="strong strong"><strong>must not</strong></span> be present). All other terms are optional. For example, this query:</p> <pre class="literallayout">quick brown +fox -news</pre> <p>states that:</p> <div class="ulist itemizedlist"> <ul class="itemizedlist"> <li class="listitem"> <code class="literal">fox</code> must be present </li> <li class="listitem"> <code class="literal">news</code> must not be present </li> <li class="listitem"> <code class="literal">quick</code> and <code class="literal">brown</code> are optional&#8201;&#8212;&#8201;their presence increases the relevance </li> </ul> </div> <p>The familiar boolean operators <code class="literal">AND</code>, <code class="literal">OR</code> and <code class="literal">NOT</code> (also written <code class="literal">&amp;&amp;</code>, <code class="literal">||</code> and <code class="literal">!</code>) are also supported but beware that they do not honor the usual precedence rules, so parentheses should be used whenever multiple operators are used together. For instance the previous query could be rewritten as:</p> <div class="variablelist"> <dl class="variablelist"> <dt> <span class="term"> <code class="literal">((quick AND fox) OR (brown AND fox) OR fox) AND NOT news</code> </span> </dt> <dd> This form now replicates the logic from the original query correctly, but the relevance scoring bears little resemblance to the original. </dd> </dl> </div> <p>In contrast, the same query rewritten using the <a class="xref" href="query-dsl-match-query.html" title="Match query"><code class="literal">match</code> query</a> would look like this:</p> <pre class="literallayout">{ "bool": { "must": { "match": "fox" }, "should": { "match": "quick brown" }, "must_not": { "match": "news" } } }</pre> </div> <div class="section"> <div class="titlepage"><div><div> <div class="position-relative"><h5 class="title"><a id="_grouping"></a>Grouping</h5><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/elasticsearch/edit/8.16/docs/reference/query-dsl/query-string-syntax.asciidoc">edit</a></div> </div></div></div> <p>Multiple terms or clauses can be grouped together with parentheses, to form sub-queries:</p> <pre class="literallayout">(quick OR brown) AND fox</pre> <p>Groups can be used to target a particular field, or to boost the result of a sub-query:</p> <pre class="literallayout">status:(active OR pending) title:(full text search)^2</pre> </div> <div class="section"> <div class="titlepage"><div><div> <div class="position-relative"><h5 class="title"><a id="_reserved_characters"></a>Reserved characters</h5><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/elasticsearch/edit/8.16/docs/reference/query-dsl/query-string-syntax.asciidoc">edit</a></div> </div></div></div> <p>If you need to use any of the characters which function as operators in your query itself (and not as operators), then you should escape them with a leading backslash. For instance, to search for <code class="literal">(1+1)=2</code>, you would need to write your query as <code class="literal">\(1\+1\)\=2</code>. When using JSON for the request body, two preceding backslashes (<code class="literal">\\</code>) are required; the backslash is a reserved escaping character in JSON strings.</p> <div class="pre_wrapper lang-python alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-python alternative">resp = client.search( index="my-index-000001", query={ "query_string": { "query": "kimchy\\!", "fields": [ "user.id" ] } }, ) print(resp)</pre> </div> <div class="pre_wrapper lang-ruby alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-ruby alternative">response = client.search( index: 'my-index-000001', body: { query: { query_string: { query: 'kimchy\\!', fields: [ 'user.id' ] } } } ) puts response</pre> </div> <div class="pre_wrapper lang-js alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-js alternative">const response = await client.search({ index: "my-index-000001", query: { query_string: { query: "kimchy\\!", fields: ["user.id"], }, }, }); console.log(response);</pre> </div> <a id="610f629d0486a64546d62402a0a5e00f"></a> <div class="pre_wrapper lang-console default has-python has-ruby has-js"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-console default has-python has-ruby has-js">GET /my-index-000001/_search { "query" : { "query_string" : { "query" : "kimchy\\!", "fields" : ["user.id"] } } }</pre> </div> <div class="console_widget has-python has-ruby has-js" data-snippet="snippets/1473.console"></div> <p>The reserved characters are: <code class="literal">+ - = &amp;&amp; || &gt; &lt; ! ( ) { } [ ] ^ " ~ * ? : \ /</code></p> <p>Failing to escape these special characters correctly could lead to a syntax error which prevents your query from running.</p> <div class="note admon"> <div class="icon"></div> <div class="admon_content"> <p><code class="literal">&lt;</code> and <code class="literal">&gt;</code> can&#8217;t be escaped at all. The only way to prevent them from attempting to create a range query is to remove them from the query string entirely.</p> </div> </div> </div> <div class="section"> <div class="titlepage"><div><div> <div class="position-relative"><h5 class="title"><a id="_whitespaces_and_empty_queries"></a>Whitespaces and empty queries</h5><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/elasticsearch/edit/8.16/docs/reference/query-dsl/query-string-syntax.asciidoc">edit</a></div> </div></div></div> <p>Whitespace is not considered an operator.</p> <p>If the query string is empty or only contains whitespaces the query will yield an empty result set.</p> </div> <div class="section"> <div class="titlepage"><div><div> <div class="position-relative"><h5 class="title"><a id="query-string-nested"></a>Avoid using the <code class="literal">query_string</code> query for nested documents</h5><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/elasticsearch/edit/8.16/docs/reference/query-dsl/query-string-query.asciidoc">edit</a></div> </div></div></div> <p><code class="literal">query_string</code> searches do not return <a class="xref" href="nested.html" title="Nested field type">nested</a> documents. To search nested documents, use the <a class="xref" href="query-dsl-nested-query.html" title="Nested query"><code class="literal">nested</code> query</a>.</p> </div> <div class="section"> <div class="titlepage"><div><div> <div class="position-relative"><h5 class="title"><a id="query-string-multi-field"></a>Search multiple fields</h5><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/elasticsearch/edit/8.16/docs/reference/query-dsl/query-string-query.asciidoc">edit</a></div> </div></div></div> <p>You can use the <code class="literal">fields</code> parameter to perform a <code class="literal">query_string</code> search across multiple fields.</p> <p>The idea of running the <code class="literal">query_string</code> query against multiple fields is to expand each query term to an OR clause like this:</p> <pre class="screen">field1:query_term OR field2:query_term | ...</pre> <p>For example, the following query</p> <div class="pre_wrapper lang-python alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-python alternative">resp = client.search( query={ "query_string": { "fields": [ "content", "name" ], "query": "this AND that" } }, ) print(resp)</pre> </div> <div class="pre_wrapper lang-ruby alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-ruby alternative">response = client.search( body: { query: { query_string: { fields: [ 'content', 'name' ], query: 'this AND that' } } } ) puts response</pre> </div> <div class="pre_wrapper lang-go alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-go alternative">res, err := es.Search( es.Search.WithBody(strings.NewReader(`{ "query": { "query_string": { "fields": [ "content", "name" ], "query": "this AND that" } } }`)), es.Search.WithPretty(), ) fmt.Println(res, err)</pre> </div> <div class="pre_wrapper lang-js alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-js alternative">const response = await client.search({ query: { query_string: { fields: ["content", "name"], query: "this AND that", }, }, }); console.log(response);</pre> </div> <a id="957d2e6ddbb9a9b16549c5e67b93b41b"></a> <div class="pre_wrapper lang-console default has-python has-ruby has-go has-js"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-console default has-python has-ruby has-go has-js">GET /_search { "query": { "query_string": { "fields": [ "content", "name" ], "query": "this AND that" } } }</pre> </div> <div class="console_widget has-python has-ruby has-go has-js" data-snippet="snippets/1474.console"></div> <p>matches the same words as</p> <div class="pre_wrapper lang-python alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-python alternative">resp = client.search( query={ "query_string": { "query": "(content:this OR name:this) AND (content:that OR name:that)" } }, ) print(resp)</pre> </div> <div class="pre_wrapper lang-ruby alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-ruby alternative">response = client.search( body: { query: { query_string: { query: '(content:this OR name:this) AND (content:that OR name:that)' } } } ) puts response</pre> </div> <div class="pre_wrapper lang-go alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-go alternative">res, err := es.Search( es.Search.WithBody(strings.NewReader(`{ "query": { "query_string": { "query": "(content:this OR name:this) AND (content:that OR name:that)" } } }`)), es.Search.WithPretty(), ) fmt.Println(res, err)</pre> </div> <div class="pre_wrapper lang-js alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-js alternative">const response = await client.search({ query: { query_string: { query: "(content:this OR name:this) AND (content:that OR name:that)", }, }, }); console.log(response);</pre> </div> <a id="3faf5e2873de340acfe0a617017db784"></a> <div class="pre_wrapper lang-console default has-python has-ruby has-go has-js"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-console default has-python has-ruby has-go has-js">GET /_search { "query": { "query_string": { "query": "(content:this OR name:this) AND (content:that OR name:that)" } } }</pre> </div> <div class="console_widget has-python has-ruby has-go has-js" data-snippet="snippets/1475.console"></div> <p>Since several queries are generated from the individual search terms, combining them is automatically done using a <code class="literal">dis_max</code> query with a <code class="literal">tie_breaker</code>. For example (the <code class="literal">name</code> is boosted by 5 using <code class="literal">^5</code> notation):</p> <div class="pre_wrapper lang-python alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-python alternative">resp = client.search( query={ "query_string": { "fields": [ "content", "name^5" ], "query": "this AND that OR thus", "tie_breaker": 0 } }, ) print(resp)</pre> </div> <div class="pre_wrapper lang-ruby alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-ruby alternative">response = client.search( body: { query: { query_string: { fields: [ 'content', 'name^5' ], query: 'this AND that OR thus', tie_breaker: 0 } } } ) puts response</pre> </div> <div class="pre_wrapper lang-go alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-go alternative">res, err := es.Search( es.Search.WithBody(strings.NewReader(`{ "query": { "query_string": { "fields": [ "content", "name^5" ], "query": "this AND that OR thus", "tie_breaker": 0 } } }`)), es.Search.WithPretty(), ) fmt.Println(res, err)</pre> </div> <div class="pre_wrapper lang-js alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-js alternative">const response = await client.search({ query: { query_string: { fields: ["content", "name^5"], query: "this AND that OR thus", tie_breaker: 0, }, }, }); console.log(response);</pre> </div> <a id="8ecefdcf8f153cf91588e9fdde8f3e6b"></a> <div class="pre_wrapper lang-console default has-python has-ruby has-go has-js"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-console default has-python has-ruby has-go has-js">GET /_search { "query": { "query_string" : { "fields" : ["content", "name^5"], "query" : "this AND that OR thus", "tie_breaker" : 0 } } }</pre> </div> <div class="console_widget has-python has-ruby has-go has-js" data-snippet="snippets/1476.console"></div> <p>Simple wildcard can also be used to search "within" specific inner elements of the document. For example, if we have a <code class="literal">city</code> object with several fields (or inner object with fields) in it, we can automatically search on all "city" fields:</p> <div class="pre_wrapper lang-python alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-python alternative">resp = client.search( query={ "query_string": { "fields": [ "city.*" ], "query": "this AND that OR thus" } }, ) print(resp)</pre> </div> <div class="pre_wrapper lang-ruby alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-ruby alternative">response = client.search( body: { query: { query_string: { fields: [ 'city.*' ], query: 'this AND that OR thus' } } } ) puts response</pre> </div> <div class="pre_wrapper lang-go alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-go alternative">res, err := es.Search( es.Search.WithBody(strings.NewReader(`{ "query": { "query_string": { "fields": [ "city.*" ], "query": "this AND that OR thus" } } }`)), es.Search.WithPretty(), ) fmt.Println(res, err)</pre> </div> <div class="pre_wrapper lang-js alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-js alternative">const response = await client.search({ query: { query_string: { fields: ["city.*"], query: "this AND that OR thus", }, }, }); console.log(response);</pre> </div> <a id="b9370fa1aa18fe4bc00cf81ef0c0d45b"></a> <div class="pre_wrapper lang-console default has-python has-ruby has-go has-js"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-console default has-python has-ruby has-go has-js">GET /_search { "query": { "query_string" : { "fields" : ["city.*"], "query" : "this AND that OR thus" } } }</pre> </div> <div class="console_widget has-python has-ruby has-go has-js" data-snippet="snippets/1477.console"></div> <p>Another option is to provide the wildcard fields search in the query string itself (properly escaping the <code class="literal">*</code> sign), for example: <code class="literal">city.\*:something</code>:</p> <div class="pre_wrapper lang-python alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-python alternative">resp = client.search( query={ "query_string": { "query": "city.\\*:(this AND that OR thus)" } }, ) print(resp)</pre> </div> <div class="pre_wrapper lang-ruby alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-ruby alternative">response = client.search( body: { query: { query_string: { query: 'city.\\*:(this AND that OR thus)' } } } ) puts response</pre> </div> <div class="pre_wrapper lang-go alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-go alternative">res, err := es.Search( es.Search.WithBody(strings.NewReader(`{ "query": { "query_string": { "query": "city.\\*:(this AND that OR thus)" } } }`)), es.Search.WithPretty(), ) fmt.Println(res, err)</pre> </div> <div class="pre_wrapper lang-js alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-js alternative">const response = await client.search({ query: { query_string: { query: "city.\\*:(this AND that OR thus)", }, }, }); console.log(response);</pre> </div> <a id="acc6cd860032167e34fa5e0c043ab3b0"></a> <div class="pre_wrapper lang-console default has-python has-ruby has-go has-js"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-console default has-python has-ruby has-go has-js">GET /_search { "query": { "query_string" : { "query" : "city.\\*:(this AND that OR thus)" } } }</pre> </div> <div class="console_widget has-python has-ruby has-go has-js" data-snippet="snippets/1478.console"></div> <div class="note admon"> <div class="icon"></div> <div class="admon_content"> <p>Since <code class="literal">\</code> (backslash) is a special character in json strings, it needs to be escaped, hence the two backslashes in the above <code class="literal">query_string</code>.</p> </div> </div> <p>The fields parameter can also include pattern based field names, allowing to automatically expand to the relevant fields (dynamically introduced fields included). For example:</p> <div class="pre_wrapper lang-python alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-python alternative">resp = client.search( query={ "query_string": { "fields": [ "content", "name.*^5" ], "query": "this AND that OR thus" } }, ) print(resp)</pre> </div> <div class="pre_wrapper lang-ruby alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-ruby alternative">response = client.search( body: { query: { query_string: { fields: [ 'content', 'name.*^5' ], query: 'this AND that OR thus' } } } ) puts response</pre> </div> <div class="pre_wrapper lang-go alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-go alternative">res, err := es.Search( es.Search.WithBody(strings.NewReader(`{ "query": { "query_string": { "fields": [ "content", "name.*^5" ], "query": "this AND that OR thus" } } }`)), es.Search.WithPretty(), ) fmt.Println(res, err)</pre> </div> <div class="pre_wrapper lang-js alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-js alternative">const response = await client.search({ query: { query_string: { fields: ["content", "name.*^5"], query: "this AND that OR thus", }, }, }); console.log(response);</pre> </div> <a id="d3dccdb15822e971ededb9f6f7d8ada1"></a> <div class="pre_wrapper lang-console default has-python has-ruby has-go has-js"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-console default has-python has-ruby has-go has-js">GET /_search { "query": { "query_string" : { "fields" : ["content", "name.*^5"], "query" : "this AND that OR thus" } } }</pre> </div> <div class="console_widget has-python has-ruby has-go has-js" data-snippet="snippets/1479.console"></div> </div> <div class="section"> <div class="titlepage"><div><div> <div class="position-relative"><h5 class="title"><a id="query-string-multi-field-parms"></a>Additional parameters for multiple field searches</h5><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/elasticsearch/edit/8.16/docs/reference/query-dsl/query-string-query.asciidoc">edit</a></div> </div></div></div> <p>When running the <code class="literal">query_string</code> query against multiple fields, the following additional parameters are supported.</p> <div class="variablelist"> <dl class="variablelist"> <dt> <span class="term"> <code class="literal">type</code> </span> </dt> <dd> <p>(Optional, string) Determines how the query matches and scores documents. Valid values are:</p> <div class="variablelist"> <dl class="variablelist"> <dt> <span class="term"> <code class="literal">best_fields</code> (Default) </span> </dt> <dd> Finds documents which match any field and uses the highest <a class="xref" href="query-filter-context.html#relevance-scores" title="Relevance scores"><code class="literal">_score</code></a> from any matching field. See <a class="xref" href="query-dsl-multi-match-query.html#type-best-fields" title="best_fields"><code class="literal">best_fields</code></a>. </dd> <dt> <span class="term"> <code class="literal">bool_prefix</code> </span> </dt> <dd> Creates a <code class="literal">match_bool_prefix</code> query on each field and combines the <code class="literal">_score</code> from each field. See <a class="xref" href="query-dsl-multi-match-query.html#type-bool-prefix" title="bool_prefix"><code class="literal">bool_prefix</code></a>. </dd> <dt> <span class="term"> <code class="literal">cross_fields</code> </span> </dt> <dd> Treats fields with the same <code class="literal">analyzer</code> as though they were one big field. Looks for each word in <span class="strong strong"><strong>any</strong></span> field. See <a class="xref" href="query-dsl-multi-match-query.html#type-cross-fields" title="cross_fields"><code class="literal">cross_fields</code></a>. </dd> <dt> <span class="term"> <code class="literal">most_fields</code> </span> </dt> <dd> Finds documents which match any field and combines the <code class="literal">_score</code> from each field. See <a class="xref" href="query-dsl-multi-match-query.html#type-most-fields" title="most_fields"><code class="literal">most_fields</code></a>. </dd> <dt> <span class="term"> <code class="literal">phrase</code> </span> </dt> <dd> Runs a <code class="literal">match_phrase</code> query on each field and uses the <code class="literal">_score</code> from the best field. See <a class="xref" href="query-dsl-multi-match-query.html#type-phrase" title="phrase and phrase_prefix"><code class="literal">phrase</code> and <code class="literal">phrase_prefix</code></a>. </dd> <dt> <span class="term"> <code class="literal">phrase_prefix</code> </span> </dt> <dd> Runs a <code class="literal">match_phrase_prefix</code> query on each field and uses the <code class="literal">_score</code> from the best field. See <a class="xref" href="query-dsl-multi-match-query.html#type-phrase" title="phrase and phrase_prefix"><code class="literal">phrase</code> and <code class="literal">phrase_prefix</code></a>. </dd> </dl> </div> <p>NOTE: Additional top-level <code class="literal">multi_match</code> parameters may be available based on the <a class="xref" href="query-dsl-multi-match-query.html#multi-match-types" title="Types of multi_match query:"><code class="literal">type</code></a> value.</p> </dd> </dl> </div> </div> </div> <div class="section"> <div class="titlepage"><div><div> <div class="position-relative"><h4 class="title"><a id="query-string-synonyms"></a>Synonyms and the <code class="literal">query_string</code> query</h4><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/elasticsearch/edit/8.16/docs/reference/query-dsl/query-string-query.asciidoc">edit</a></div> </div></div></div> <p>The <code class="literal">query_string</code> query supports multi-terms synonym expansion with the <a class="xref" href="analysis-synonym-graph-tokenfilter.html" title="Synonym graph token filter">synonym_graph</a> token filter. When this filter is used, the parser creates a phrase query for each multi-terms synonyms. For example, the following synonym: <code class="literal">ny, new york</code> would produce:</p> <p><code class="literal">(ny OR ("new york"))</code></p> <p>It is also possible to match multi terms synonyms with conjunctions instead:</p> <div class="pre_wrapper lang-php alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-php alternative">$params = [ 'body' =&gt; [ 'query' =&gt; [ 'query_string' =&gt; [ 'default_field' =&gt; 'title', 'query' =&gt; 'ny city', 'auto_generate_synonyms_phrase_query' =&gt; false, ], ], ], ]; $response = $client-&gt;search($params);</pre> </div> <div class="pre_wrapper lang-python alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-python alternative">resp = client.search( query={ "query_string": { "default_field": "title", "query": "ny city", "auto_generate_synonyms_phrase_query": False } }, ) print(resp)</pre> </div> <div class="pre_wrapper lang-ruby alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-ruby alternative">response = client.search( body: { query: { query_string: { default_field: 'title', query: 'ny city', auto_generate_synonyms_phrase_query: false } } } ) puts response</pre> </div> <div class="pre_wrapper lang-go alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-go alternative">res, err := es.Search( es.Search.WithBody(strings.NewReader(`{ "query": { "query_string": { "default_field": "title", "query": "ny city", "auto_generate_synonyms_phrase_query": false } } }`)), es.Search.WithPretty(), ) fmt.Println(res, err)</pre> </div> <div class="pre_wrapper lang-js alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-js alternative">const response = await client.search({ query: { query_string: { default_field: "title", query: "ny city", auto_generate_synonyms_phrase_query: false, }, }, }); console.log(response);</pre> </div> <a id="f32f0c19b42de3b87dd764fe4ca17e7c"></a> <div class="pre_wrapper lang-console default has-php has-python has-ruby has-go has-js"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-console default has-php has-python has-ruby has-go has-js">GET /_search { "query": { "query_string" : { "default_field": "title", "query" : "ny city", "auto_generate_synonyms_phrase_query" : false } } }</pre> </div> <div class="console_widget has-php has-python has-ruby has-go has-js" data-snippet="snippets/1480.console"></div> <p>The example above creates a boolean query:</p> <p><code class="literal">(ny OR (new AND york)) city</code></p> <p>that matches documents with the term <code class="literal">ny</code> or the conjunction <code class="literal">new AND york</code>. By default the parameter <code class="literal">auto_generate_synonyms_phrase_query</code> is set to <code class="literal">true</code>.</p> </div> <div class="section"> <div class="titlepage"><div><div> <div class="position-relative"><h4 class="title"><a id="query-string-min-should-match"></a>How <code class="literal">minimum_should_match</code> works</h4><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/elasticsearch/edit/8.16/docs/reference/query-dsl/query-string-query.asciidoc">edit</a></div> </div></div></div> <p>The <code class="literal">query_string</code> splits the query around each operator to create a boolean query for the entire input. You can use <code class="literal">minimum_should_match</code> to control how many "should" clauses in the resulting query should match.</p> <div class="pre_wrapper lang-python alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-python alternative">resp = client.search( query={ "query_string": { "fields": [ "title" ], "query": "this that thus", "minimum_should_match": 2 } }, ) print(resp)</pre> </div> <div class="pre_wrapper lang-ruby alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-ruby alternative">response = client.search( body: { query: { query_string: { fields: [ 'title' ], query: 'this that thus', minimum_should_match: 2 } } } ) puts response</pre> </div> <div class="pre_wrapper lang-go alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-go alternative">res, err := es.Search( es.Search.WithBody(strings.NewReader(`{ "query": { "query_string": { "fields": [ "title" ], "query": "this that thus", "minimum_should_match": 2 } } }`)), es.Search.WithPretty(), ) fmt.Println(res, err)</pre> </div> <div class="pre_wrapper lang-js alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-js alternative">const response = await client.search({ query: { query_string: { fields: ["title"], query: "this that thus", minimum_should_match: 2, }, }, }); console.log(response);</pre> </div> <a id="472ec8c57fec8457e31fe6dd7f6e3713"></a> <div class="pre_wrapper lang-console default has-python has-ruby has-go has-js"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-console default has-python has-ruby has-go has-js">GET /_search { "query": { "query_string": { "fields": [ "title" ], "query": "this that thus", "minimum_should_match": 2 } } }</pre> </div> <div class="console_widget has-python has-ruby has-go has-js" data-snippet="snippets/1481.console"></div> <p>The example above creates a boolean query:</p> <p><code class="literal">(title:this title:that title:thus)~2</code></p> <p>that matches documents with at least two of the terms <code class="literal">this</code>, <code class="literal">that</code> or <code class="literal">thus</code> in the single field <code class="literal">title</code>.</p> </div> <div class="section"> <div class="titlepage"><div><div> <div class="position-relative"><h4 class="title"><a id="query-string-min-should-match-multi"></a>How <code class="literal">minimum_should_match</code> works for multiple fields</h4><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/elasticsearch/edit/8.16/docs/reference/query-dsl/query-string-query.asciidoc">edit</a></div> </div></div></div> <div class="pre_wrapper lang-python alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-python alternative">resp = client.search( query={ "query_string": { "fields": [ "title", "content" ], "query": "this that thus", "minimum_should_match": 2 } }, ) print(resp)</pre> </div> <div class="pre_wrapper lang-ruby alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-ruby alternative">response = client.search( body: { query: { query_string: { fields: [ 'title', 'content' ], query: 'this that thus', minimum_should_match: 2 } } } ) puts response</pre> </div> <div class="pre_wrapper lang-go alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-go alternative">res, err := es.Search( es.Search.WithBody(strings.NewReader(`{ "query": { "query_string": { "fields": [ "title", "content" ], "query": "this that thus", "minimum_should_match": 2 } } }`)), es.Search.WithPretty(), ) fmt.Println(res, err)</pre> </div> <div class="pre_wrapper lang-js alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-js alternative">const response = await client.search({ query: { query_string: { fields: ["title", "content"], query: "this that thus", minimum_should_match: 2, }, }, }); console.log(response);</pre> </div> <a id="151d2b11807ec684b0c01aa89189a801"></a> <div class="pre_wrapper lang-console default has-python has-ruby has-go has-js"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-console default has-python has-ruby has-go has-js">GET /_search { "query": { "query_string": { "fields": [ "title", "content" ], "query": "this that thus", "minimum_should_match": 2 } } }</pre> </div> <div class="console_widget has-python has-ruby has-go has-js" data-snippet="snippets/1482.console"></div> <p>The example above creates a boolean query:</p> <p><code class="literal">((content:this content:that content:thus) | (title:this title:that title:thus))</code></p> <p>that matches documents with the disjunction max over the fields <code class="literal">title</code> and <code class="literal">content</code>. Here the <code class="literal">minimum_should_match</code> parameter can&#8217;t be applied.</p> <div class="pre_wrapper lang-python alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-python alternative">resp = client.search( query={ "query_string": { "fields": [ "title", "content" ], "query": "this OR that OR thus", "minimum_should_match": 2 } }, ) print(resp)</pre> </div> <div class="pre_wrapper lang-ruby alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-ruby alternative">response = client.search( body: { query: { query_string: { fields: [ 'title', 'content' ], query: 'this OR that OR thus', minimum_should_match: 2 } } } ) puts response</pre> </div> <div class="pre_wrapper lang-go alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-go alternative">res, err := es.Search( es.Search.WithBody(strings.NewReader(`{ "query": { "query_string": { "fields": [ "title", "content" ], "query": "this OR that OR thus", "minimum_should_match": 2 } } }`)), es.Search.WithPretty(), ) fmt.Println(res, err)</pre> </div> <div class="pre_wrapper lang-js alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-js alternative">const response = await client.search({ query: { query_string: { fields: ["title", "content"], query: "this OR that OR thus", minimum_should_match: 2, }, }, }); console.log(response);</pre> </div> <a id="ad2416ca0581316cee6c63129685bca5"></a> <div class="pre_wrapper lang-console default has-python has-ruby has-go has-js"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-console default has-python has-ruby has-go has-js">GET /_search { "query": { "query_string": { "fields": [ "title", "content" ], "query": "this OR that OR thus", "minimum_should_match": 2 } } }</pre> </div> <div class="console_widget has-python has-ruby has-go has-js" data-snippet="snippets/1483.console"></div> <p>Adding explicit operators forces each term to be considered as a separate clause.</p> <p>The example above creates a boolean query:</p> <p><code class="literal">((content:this | title:this) (content:that | title:that) (content:thus | title:thus))~2</code></p> <p>that matches documents with at least two of the three "should" clauses, each of them made of the disjunction max over the fields for each term.</p> </div> <div class="section"> <div class="titlepage"><div><div> <div class="position-relative"><h4 class="title"><a id="query-string-min-should-match-cross"></a>How <code class="literal">minimum_should_match</code> works for cross-field searches</h4><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/elasticsearch/edit/8.16/docs/reference/query-dsl/query-string-query.asciidoc">edit</a></div> </div></div></div> <p>A <code class="literal">cross_fields</code> value in the <code class="literal">type</code> field indicates fields with the same analyzer are grouped together when the input is analyzed.</p> <div class="pre_wrapper lang-python alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-python alternative">resp = client.search( query={ "query_string": { "fields": [ "title", "content" ], "query": "this OR that OR thus", "type": "cross_fields", "minimum_should_match": 2 } }, ) print(resp)</pre> </div> <div class="pre_wrapper lang-ruby alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-ruby alternative">response = client.search( body: { query: { query_string: { fields: [ 'title', 'content' ], query: 'this OR that OR thus', type: 'cross_fields', minimum_should_match: 2 } } } ) puts response</pre> </div> <div class="pre_wrapper lang-go alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-go alternative">res, err := es.Search( es.Search.WithBody(strings.NewReader(`{ "query": { "query_string": { "fields": [ "title", "content" ], "query": "this OR that OR thus", "type": "cross_fields", "minimum_should_match": 2 } } }`)), es.Search.WithPretty(), ) fmt.Println(res, err)</pre> </div> <div class="pre_wrapper lang-js alternative"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-js alternative">const response = await client.search({ query: { query_string: { fields: ["title", "content"], query: "this OR that OR thus", type: "cross_fields", minimum_should_match: 2, }, }, }); console.log(response);</pre> </div> <a id="25576b6773322f0929d4c635a940dba0"></a> <div class="pre_wrapper lang-console default has-python has-ruby has-go has-js"> <div class="console_code_copy" title="Copy to clipboard"></div> <pre class="programlisting prettyprint lang-console default has-python has-ruby has-go has-js">GET /_search { "query": { "query_string": { "fields": [ "title", "content" ], "query": "this OR that OR thus", "type": "cross_fields", "minimum_should_match": 2 } } }</pre> </div> <div class="console_widget has-python has-ruby has-go has-js" data-snippet="snippets/1484.console"></div> <p>The example above creates a boolean query:</p> <p><code class="literal">(blended(terms:[field2:this, field1:this]) blended(terms:[field2:that, field1:that]) blended(terms:[field2:thus, field1:thus]))~2</code></p> <p>that matches documents with at least two of the three per-term blended queries.</p> </div> <div class="section"> <div class="titlepage"><div><div> <div class="position-relative"><h4 class="title"><a id="_allow_expensive_queries"></a>Allow expensive queries</h4><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/elasticsearch/edit/8.16/docs/reference/query-dsl/query-string-query.asciidoc">edit</a></div> </div></div></div> <p>Query string query can be internally be transformed to a <a class="xref" href="query-dsl-prefix-query.html" title="Prefix query"><code class="literal">prefix query</code></a> which means that if the prefix queries are disabled as explained <a class="xref" href="query-dsl-prefix-query.html#prefix-query-allow-expensive-queries" title="Allow expensive queries">here</a> the query will not be executed and an exception will be thrown.</p> </div> </div> </div> </div> </div><div class="navfooter"> <span class="prev"> <a href="query-dsl-multi-match-query.html">« Multi-match query</a> </span> <span class="next"> <a href="query-dsl-simple-query-string-query.html">Simple query string query »</a> </span> </div> <!-- end body --> </div> <div class="col-12 order-3 col-lg-2 order-lg-3 h-almost-full-lg sticky-top-lg" id="right_col"> <div id="sticky_content"> <!-- The OTP is appended here --> <div class="row"> <div class="col-0 col-md-4 col-lg-0" id="bottom_left_col"></div> <div class="col-12 col-md-8 col-lg-12"> <div id="rtpcontainer"> <div class="mktg-promo" id="most-popular"> <p class="aside-heading">Most Popular</p> <div class="pb-2"> <p class="media-type">Video</p> <a href="https://www.elastic.co/webinars/getting-started-elasticsearch?page=docs&placement=top-video"> <p class="mb-0">Get Started with Elasticsearch</p> </a> </div> <div class="pb-2"> <p class="media-type">Video</p> <a href="https://www.elastic.co/webinars/getting-started-kibana?page=docs&placement=top-video"> <p class="mb-0">Intro to Kibana</p> </a> </div> <div class="pb-2"> <p class="media-type">Video</p> <a href="https://www.elastic.co/webinars/introduction-elk-stack?page=docs&placement=top-video"> <p class="mb-0">ELK for Logs & Metrics</p> </a> </div> </div> </div> <!-- Feedback widget --> <div id="feedbackWidgetContainer"></div> </div> </div> </div> </div> </div> </div> </section> </div> <div id='elastic-footer'></div> <script src='https://www.elastic.co/elastic-footer.js'></script> <!-- Footer Section end--> </section> </div> <!-- Feedback modal --> <div id="feedbackModalContainer"></div> <script src="/guide/static/jquery.js"></script> <script type="text/javascript" src="/guide/static/docs-v1.js"></script> <script type="text/javascript"> window.initial_state = {"alternatives":{"console":{"php":{"hasAny":true},"python":{"hasAny":true},"ruby":{"hasAny":true},"go":{"hasAny":true},"js":{"hasAny":true}}}}</script> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10