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:

  1. GET shakespeare/_search
  2. {
  3. "query": {
  4. "query_string": {
  5. "query": "speaker:KING AND play_name: *well"
  6. }
  7. }
  8. }

Parameters

The following table lists the parameters that query_string query supports. All parameters except query are optional.

ParameterData typeDescription
queryStringThe query string to use for search. Required.
fieldsString arrayThe list of fields to search (for example, “fields”: [“title^4”, “description”]). Supports wildcards.
default_fieldStringThe 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_field index setting. By default, the index.query.default_field is , which means extract all fields eligible for term query and filter the metadata fields. The extracted fields are combined into a query if the prefix is not specified. Eligible fields do not include nested documents. Searching all eligible fields could be a resource-intensive operation. The indices.query.bool.max_clause_count search 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 for indices.query.bool.max_clause_count is 4,096.
allow_leading_wildcardBooleanSpecifies whether and ? are allowed as first characters of a search term. Default is true.
analyze_wildcardBooleanSpecifies whether OpenSearch should attempt to analyze wildcard terms. Default is false.
analyzerStringThe 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 the default_field, the analyzer is the default analyzer for the index.
quote_analyzerStringThe analyzer used to tokenize quoted text in the query string. Overrides the analyzer parameter for quoted text. Default is the search_quote_analyzer specified for the default_field.
quote_field_suffixStringThis 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_suffix is .exact and you search for \”lightly\” in the title field, OpenSearch searches for the word lightly in the title.exact field. This second field might use a different type (for example, keyword rather than text) or a different analyzer.
phrase_slopIntegerThe maximum number of words that are allowed between the matched words. If phrase_slop is 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_matchPositive or negative integer, positive or negative percentage, combinationIf the query string contains multiple search terms and you used the or operator, the number of terms that need to match for the document to be considered a match. For example, if minimum_should_match is 2, “wind often rising” does not match “The Wind Rises.” If minimum_should_match is 1, it matches.
rewriteStringDetermines 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, and top_terms_blended_freqs_N. Default is constant_score.
auto_generate_synonyms_phrase_queryBooleanSpecifies whether to create match queries automatically for multi-term synonyms. Default is true.
boostFloating-pointBoosts 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_operatorStringThe default Boolean operator used if no operators are specified. Valid values are:
- OR: The string to be is interpreted as to OR be
- AND: The string to be is interpreted as to AND be
Default is OR.
enable_position_incrementsBooleanWhen 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.
fuzzinessStringThe 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 wined and wind is 1. Valid values are non-negative integers or AUTO. The default, AUTO, chooses a value based on the length of each term and is a good choice for most use cases.
fuzzy_transpositionsBooleanSetting fuzzy_transpositions to true (default) adds swaps of adjacent characters to the insert, delete, and substitute operations of the fuzziness option. For example, the distance between wind and wnid is 1 if fuzzy_transpositions is true (swap “n” and “i”) and 2 if it is false (delete “n”, insert “n”). If fuzzy_transpositions is false, rewind and wnid have the same distance (2) from wind, despite the more human-centric opinion that wnid is an obvious typo. The default is a good choice for most use cases.
fuzzy_max_expansionsPositive integerThe maximum number of terms the fuzzy query will match. Default is 50.
lenientBooleanSetting lenient to 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 type float. Default is false.
max_determinized_statesPositive integerThe 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_zoneStringSpecifies 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, set time_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 is UTC.

Query string queries - 图1