You're viewing version 2.4 of the OpenSearch documentation. This version is no longer maintained. For the latest version, see the current documentation. For information about OpenSearch version maintenance, see Release Schedule and Maintenance Policy.
Query string queries
A query_string query parses the query string based on the query_string syntax. It lets you create powerful yet concise queries that can incorporate wildcards and search multiple fields.
Example
The following query searches for the speaker KING in the play name that ends with well:
GET shakespeare/_search
{
 "query": {
    "query_string": {
      "query": "speaker:KING  AND play_name: *well"
    }
  }
}
Parameters
The following table lists the parameters that query_string query supports. All parameters except query are optional.
| Parameter | Data type | Description | 
|---|---|---|
| query | String | The query string to use for search. Required. | 
| fields | String array | The list of fields to search (for example, "fields": ["title^4", "description"]). Supports wildcards. | 
| default_field | String | The field in which to search if the field is not specified in the query string. Supports wildcards. Defaults to the value specified in the index.query.default_fieldindex setting. By default, theindex.query.default_fieldis*, which means extract all fields eligible for term query and filter the metadata fields. The extracted fields are combined into a query if theprefixis not specified. Eligible fields do not include nested documents. Searching all eligible fields could be a resource-intensive operation. Theindices.query.bool.max_clause_countsearch setting defines the maximum value for the product of the number of fields and the number of terms that can be queried at one time. The default value forindices.query.bool.max_clause_countis 4,096. | 
| allow_leading_wildcard | Boolean | Specifies whether *and?are allowed as first characters of a search term. Default istrue. | 
| analyze_wildcard | Boolean | Specifies whether OpenSearch should attempt to analyze wildcard terms. Default is false. | 
| analyzer | String | The analyzer used to tokenize the query string text. Default is the index-time analyzer specified for the default_field. If no analyzer is specified for thedefault_field, theanalyzeris the default analyzer for the index. | 
| quote_analyzer | String | The analyzer used to tokenize quoted text in the query string. Overrides the analyzerparameter for quoted text. Default is thesearch_quote_analyzerspecified for thedefault_field. | 
| quote_field_suffix | String | This option lets you search for exact matches (surrounded with quotation marks) using a different analysis method than non-exact matches use. For example, if quote_field_suffixis.exactand you search for\"lightly\"in thetitlefield, OpenSearch searches for the wordlightlyin thetitle.exactfield. This second field might use a different type (for example,keywordrather thantext) or a different analyzer. | 
| phrase_slop | Integer | The maximum number of words that are allowed between the matched words. If phrase_slopis 2, a maximum of two words is allowed between matched words in a phrase. Transposed words have a slop of 2. Default is 0 (an exact phrase match where matched words must be next to each other). | 
| minimum_should_match | Positive or negative integer, positive or negative percentage, combination | If the query string contains multiple search terms and you used the oroperator, the number of terms that need to match for the document to be considered a match. For example, ifminimum_should_matchis 2, “wind often rising” does not match “The Wind Rises.” Ifminimum_should_matchis 1, it matches. | 
| rewrite | String | Determines how OpenSearch rewrites and scores multi-term queries. Valid values are constant_score,scoring_boolean,constant_score_boolean,top_terms_N,top_terms_boost_N, andtop_terms_blended_freqs_N. Default isconstant_score. | 
| auto_generate_synonyms_phrase_query | Boolean | Specifies whether to create match queries automatically for multi-term synonyms. Default is true. | 
| boost | Floating-point | Boosts the clause by the given multiplier. Values less than 1.0 decrease relevance, and values greater than 1.0 increase relevance. Default is 1.0. | 
| default_operator | String | The default Boolean operator used if no operators are specified. Valid values are: - OR: The stringto beis interpreted asto OR be- AND: The stringto beis interpreted asto AND beDefault is OR. | 
| enable_position_increments | Boolean | When true, resulting queries are aware of position increments. This setting is useful when the removal of stop words leaves an unwanted “gap” between terms. Default is true. | 
| fuzziness | String | The number of character edits (insert, delete, substitute) that it takes to change one word to another when determining whether a term matched a value. For example, the distance between winedandwindis 1. Valid values are non-negative integers orAUTO. The default,AUTO, chooses a value based on the length of each term and is a good choice for most use cases. | 
| fuzzy_transpositions | Boolean | Setting fuzzy_transpositionstotrue(default) adds swaps of adjacent characters to the insert, delete, and substitute operations of thefuzzinessoption. For example, the distance betweenwindandwnidis 1 iffuzzy_transpositionsis true (swap “n” and “i”) and 2 if it is false (delete “n”, insert “n”). Iffuzzy_transpositionsis false,rewindandwnidhave the same distance (2) fromwind, despite the more human-centric opinion thatwnidis an obvious typo. The default is a good choice for most use cases. | 
| fuzzy_max_expansions | Positive integer | The maximum number of terms the fuzzy query will match. Default is 50. | 
| lenient | Boolean | Setting lenientto true lets you ignore data type mismatches between the query and the document field. For example, a query string of “8.2” could match a field of typefloat. Default isfalse. | 
| max_determinized_states | Positive integer | The maximum number of “states” (a measure of complexity) that Lucene can create for query strings that contain regular expressions (for example, "query": "/wind.+?/"). Larger numbers allow for queries that use more memory. Default is 10,000. | 
| time_zone | String | Specifies the number of hours to offset the desired time zone from UTC. You need to indicate the time zone offset number if the query string contains a date range. For example, settime_zone": "-08:00"for a query with a date range such as"query": "wind rises release_date[2012-01-01 TO 2014-01-01]"). The default time zone format used to specify number of offset hours isUTC. |