The query string “mini-language” is used by the Query String Query and by the q query string parameter in the search API. The query string is parsed into a series of terms and operators. A term can be a single word — quick or brown — or a phrase, surrounded by double quotes — "quick brown" — which searches for all the words in the phrase, in the same order. Operators allow you to customize the search — the available options are explained below.
computer
or its part (from begining):comp
By default search will be performed on these fields:"quick brown"
fox brown bar
For searching documents with all words you should enable "All words" checkbox.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 "a* b* c*".
Warning
Allowing a wildcard at the beginning of a word (eg "*ing") is particularly heavy, because all terms in the index need
to be examined, just in case they match.
status:new
title:(quick brown)
author:"John Smith"
book.\*:(quick brown)
_missing_:title
_exists_:title
You can search issues, projects, news, documents, wiki_pages and messages by attachments. Here an example for searching container with attachment filename "somefile.pdf":
attachments.filename:somefile.pdf
List of attachment fieldsauthor:/joh?n(ath[oa]n)/
The supported regular expression syntax is explained in Regular expression syntax.
Warning
A query string such as the following would force Elasticsearch to visit every term in the index:
/.*n/
Use with caution!quikc~ brwn~ foks~
This 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 2, but an edit distance of 1 should be sufficient to catch 80% of all human misspellings. It can be specified as:quikc~1
"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 "quick fox" would be considered more relevant than "quick brown fox".Ranges can be specified for date, numeric or string fields. Inclusive ranges are specified with square brackets [min TO max] and exclusive ranges with curly brackets {min TO max}.
All days in 2013:datetime:[2013-01-01 TO 2013-12-31]
Numbers 1..5count:[1 TO 5]
Tags between alpha and omega, excluding alpha and omega:tags:{alpha TO omega}
Numbers from 10 upwardscount:[10 TO *]
Dates before 2012datetime:{* TO 2012-01-01}
Curly and square brackets can be combined:count:[1..5}
Ranges with one side unbounded can use the following syntax:
age:>10
age:>=10
age:<10
age:<=10
age:(>=10 AND <20)
age:(+>=10 +<20)
quick^2 fox
The default boost value is 1, but can be any positive floating point number. Boosts between 0 and 1 reduce relevance."john smith"^2 (foo bar)^4
By default, all terms are optional, as long as one term matches. A search for foo bar baz will find any document that contains one or more of foo or bar or baz. We have already discussed the default_operator above which allows you to force all terms to be required, but there are also boolean operators which can be used in the query string itself to provide more control.
The preferred operators are + (this term must be present) and - (this term must not be present). All other terms are optional. For example, this query:
quick brown +fox -news
states that:
fox must be present
news must not be present
quick and brown are optional — their presence increases the relevance
The familiar operators AND, OR and NOT (also written &&, || and !) are also supported. However, the effects of these operators can be more complicated than is obvious at first glance. NOT takes precedence over AND, which takes precedence over OR. While the + and - only affect the term to the right of the operator, AND and OR can affect the terms to the left and right.
(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
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 (1+1)=2, you would need to write your query as \(1\+1\)=2.
The reserved characters are: + - && || ! ( ) { } [ ] ^ " ~ * ? : \ /
Failing to escape these special characters correctly could lead to a syntax error which prevents your query from running.
If the query string is empty or only contains whitespaces the query string is interpreted as a no_docs_query and will yield an empty result set.