-
Notifications
You must be signed in to change notification settings - Fork 0
Query String Query
A query that uses a query parser in order to parse its content. Here is an example:
{
"query_string" : {
"default_field" : "content",
"query" : "this AND that OR thus"
}
}The query_string top level parameters include:
-
query: The actual query to be parsed. -
default_field: The default field for query terms if no prefix field is specified. Defaults to the_allfield. -
default_operator: The default operator used if no explicit operator is specified. For example, with a default operator ofOR, the querycapital of Hungaryis translated tocapital OR of OR Hungary, and with default operator ofAND, the same query is translated tocapital AND of AND Hungary. The default value isOR. -
analyzer: The analyzer name used to analyze the query string. -
allow_leading_wildcard: When set,*or?are allowed as the first character. Defaults totrue. -
lowercase_expanded_terms: Whether terms of wildcard, prefix, fuzzy, and range queries are to be automatically lower-cased or not (since they are not analyzed). Default ittrue. -
enable_position_increments: Set totrueto enable position increments in result queries. Defaults totrue. -
fuzzy_prefix_length: Set the prefix length for fuzzy queries. Default is0. -
fuzzy_min_sim: Set the minimum similarity for fuzzy queries. Defaults to0.5 -
phrase_slop: Sets the default slop for phrases. If zero, then exact phrase matches are required. Default value is0. -
boost: Sets the boost value of the query. Defaults to1.0.
The query_string query can also run against multiple fields. The idea of running the query_string query against multiple fields is by internally creating several queries for the same query string, each with default_field that match the fields provided. Since several queries are generated, combining them can be automatically done either using a dis_max query or a simple bool query. For example (the name is boosted by 5 using ^5 notation):
{
"query_string" : {
"fields" : ["content", "name^5"],
"query" : "this AND that OR thus",
"use_dis_max" : true
}
}When running the query_string query against multiple fields, the following additional parameters are allowed:
-
use_dis_max: Should the queries be combined usingdis_max(set it totrue), or aboolquery (set it tofalse). Defaults totrue. -
tie_breaker: When usingdis_max, the disjunction max tie breaker. Defaults to0.
The fields parameter can also include pattern based field names, allowing to automatically expand to the relevant fields (dynamically introduced fields included). For example:
{
"query_string" : {
"fields" : ["content", "name.*^5"],
"query" : "this AND that OR thus",
"use_dis_max" : true
}
}There are several syntax extensions to the Lucene query language.
The _exists_ and _missing_ syntax allows to control docs that have fields that exists within them (have a value) and missing. The syntax is: _exists_:field1, _missing_:field and can be used anywhere a query string is used.