Show
Query string queryeditThis page contains information about the Returns documents based on a provided query string, using a parser with a strict syntax. This query uses a syntax to parse and split the provided
query string based on operators, such as You can use the Because it returns an error for any invalid syntax, we don’t recommend using the If you don’t need to support a query syntax, consider using the When running the following search, the response = client.search( body: { query: { query_string: { query: '(new york city) OR (big apple)', default_field: 'content' } } } ) puts response 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) GET /_search { "query": { "query_string": { "query": "(new york city) OR (big apple)", "default_field": "content" } } } Top-level parameters for query_stringedit (Optional, string) Default field to search if no field is provided in the query string. Supports wildcards ( Defaults to the
Searching across all eligible fields does not include
nested documents. Use a For mappings with a large number of fields, searching across all eligible fields could be expensive. There is a limit on the
number of fields times terms that can be queried at once. It is defined by the allow_leading_wildcard (Optional, Boolean) If true , the wildcard characters * and ? are allowed as the first character of the query string. Defaults to true . analyze_wildcard
(Optional, Boolean) If true , the query attempts to analyze wildcard terms in the query string. Defaults to false . analyzer (Optional, string) Analyzer used to convert text in the query string into tokens. Defaults to the
index-time analyzer mapped for the default_field . If no analyzer is mapped, the index’s default analyzer is used. auto_generate_synonyms_phrase_query (Optional, Boolean) If true ,
match phrase queries are automatically created for multi-term synonyms. Defaults to true . See Synonyms and the query_string query for an example.
boost (Optional, float) Floating point number used to decrease or increase the relevance scores of the query. Defaults to Boost values are relative to the default value of default_operator (Optional, string) Default boolean logic used to interpret text in the query string if no operators are specified. Valid values are: enable_position_increments
(Optional, Boolean) If true , enable position increments in queries constructed from a query_string search. Defaults to true . fields (Optional, array of strings) Array of fields to search. Supports wildcards ( You can use this parameter query to search across multiple fields. See Search multiple fields. fuzziness (Optional, string) Maximum edit distance allowed for fuzzy matching. For fuzzy syntax, see
Fuzziness. fuzzy_max_expansions (Optional, integer) Maximum number of terms to which the query expands for fuzzy matching. Defaults to 50 . fuzzy_prefix_length (Optional, integer) Number of beginning characters left unchanged for fuzzy matching. Defaults to 0 .
fuzzy_transpositions (Optional, Boolean) If true , edits for fuzzy matching include transpositions of two adjacent characters (ab → ba). Defaults to true . lenient (Optional, Boolean) If true , format-based errors, such as providing a text value for a numeric field, are ignored. Defaults to false .
max_determinized_states (Optional, integer) Maximum number of automaton states required for the query. Default is Elasticsearch uses Apache Lucene internally to parse regular expressions. Lucene converts each regular expression to a finite automaton containing a number of determinized states. 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. minimum_should_match (Optional, string) Minimum number of clauses that must match for a document to be returned. See the minimum_should_match parameter for
valid values and more information. See How minimum_should_match works for an example. quote_analyzer (Optional, string) Analyzer used to convert quoted text
in the query string into tokens. Defaults to the For quoted text, this parameter overrides the analyzer specified in the phrase_slop (Optional, integer) Maximum number of positions allowed between matching tokens for phrases. Defaults to 0 .
If 0 , exact phrase matches are required. Transposed terms have a slop of 2 . quote_field_suffix (Optional, string) Suffix appended to quoted text in the query string. You can use this suffix to use a different analysis method for exact matches. See Mixing exact search with stemming. rewrite (Optional, string) Method used to rewrite the query. For valid values and more information, see the rewrite parameter. time_zone (Optional, string) Coordinated Universal
Time (UTC) offset or IANA time zone used to convert Valid values are ISO 8601 UTC offsets, such as The Query string syntaxeditThe query string “mini-language” is used by the
Query string and by the The query string is parsed into a series of terms and operators. A term can be a single word — Operators allow you to customize the search — the available options are explained below. You can specify fields to search in the query syntax:
Wildcard searches can be run on individual terms, using qu?ck bro* Be aware that wildcard queries can use an enormous amount of memory and perform very badly — just think how many terms need to be queried to match the query string Pure wildcards { "field": "" } ... and would not match if the field is missing or set with an explicit null value like the following: { "field": null } Allowing a wildcard at the beginning of a word (eg 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. By setting Regular expressionseditRegular expression patterns can be embedded in the query string by wrapping them in forward-slashes ( name:/joh?n(ath[oa]n)/ The supported regular expression syntax is explained in Regular expression syntax. The /.*n/ Use with caution! You can run
quikc~ brwn~ foks~ For these queries, the query string is normalized. If present, only certain filters from the analyzer are applied. For a list of applicable filters, see Normalizers. The query uses the Damerau-Levenshtein distance 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. The default
edit distance is quikc~1 Avoid mixing fuzziness with wildcardsMixing fuzzy and
wildcard operators is not supported. When mixed, one of the operators is not applied. For example, you can search for Proximity searcheseditWhile a phrase query (eg "fox quick"~5 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 Ranges can be specified for date, numeric or string fields. Inclusive ranges are specified with square brackets
Curly and square brackets can be combined:
Ranges with one side unbounded can use the following syntax: age:>10 age:>=10 age:<10 age:<=10 To combine an upper and lower bound with the simplified syntax, you would need to join two clauses with an age:(>=10 AND <20) age:(+>=10 +<20) The parsing of ranges in query strings can be complex and error prone. It is much more reliable to use an explicit Use the boost operator quick^2 fox The default Boosts can also be applied to phrases or to groups: "john smith"^2 (foo bar)^4 Boolean operatorseditBy default, all terms are optional, as long as one term matches. A search for The preferred operators are quick brown +fox -news states that:
The familiar boolean operators In contrast, the same query rewritten using the { "bool": { "must": { "match": "fox" }, "should": { "match": "quick brown" }, "must_not": { "match": "news" } } } Multiple terms or clauses can be grouped together with parentheses, to form sub-queries: (quick OR brown) AND fox Groups can be used to target a particular field, or to boost the result of a sub-query: status:(active OR pending) title:(full text search)^2 Reserved characterseditIf 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 GET /my-index-000001/_search { "query" : { "query_string" : { "query" : "kimchy\\!", "fields" : ["user.id"] } } } The reserved characters are: Failing to escape these special characters correctly could lead to a syntax error which prevents your query from running.
Whitespaces and empty querieseditWhitespace is not considered an operator. If the query string is empty or only contains whitespaces the query will yield an empty result set. Avoid using the |