You can build up complex queries using Boolean search operators - by using these operators, you can narrow your search, combine terms, or exclude terms. Besides the primary AND, OR, and AND NOT operators, here are others which may be helpful:
Symbol | Use of Symbol |
---|---|
" |
Term enclosed in quotes must appear exactly as provided. Example: “towel” will find towel, but not towels. |
+ |
Term after “+” must be in the result. Example: +tea cricket requires that results that must contain the term tea in them, and may have the term cricket. |
- |
Term after “-” must not be in the result. Example: -tea cricket requires that results that must not contain the term tea in them, and may have the term cricket. |
? |
Single character wildcard. Example: p?per will find paper and piper, but not pepper. |
* |
Multiple character wildcard. Example: galax* will find galaxy and galaxies, but not galactic. |
~ |
Fuzzy search. Will return results with words similar to the term. Example: fjord~ will find fjord, fjords, ford, form, fonds, etc. |
&& |
Boolean operator. Can be used in place of AND. Will cause an error if combined with spelled-out operators. Example: Arthur && Ford AND Zaphod will fail; Arthur && Ford && Zaphod will succeed. |
! |
Boolean operator. Can be used in place of NOT. Will cause an error if combined with spelled-out operators. |
^ |
Boost relevance. Multiplies the relevance of the preceding term by the number following the symbol, affecting the sorting of the search results. Example: paranoid android^5 gives results containing the term “android” 5x the relevance as results containing only the word “paranoid”, and will sort them closer to the start of the search results. |
\ |
Escapes the immediately following character, so that it is treated as text, rather than as a special character. For example, to search for “(1+1):2”, use the following: \(1\+1\)\:2 |
() |
Used to group search clauses. This can be useful if you want to control the precedence of boolean operators for a query, e.g. (coffee NOT tea) OR cream will return different results than coffee NOT (tea OR cream). Without grouping, by default in Elasticsearch, NOT takes precedence over AND, which takes precedence over OR. |
[] |
Closed interval range search. Example: [“Frogstar” TO “Magrathea”] will return results in the alphabetic range between “Frogstar” and “Magrathea”, including”Frogstar” and “Magrathea”. |
{} |
Open interval range search. Example: {“Frogstar” TO “Magrathea”} will return all results in the alphabetic range between “Frogstar” and “Magrathea”, excluding”Frogstar” and “Magrathea”. |