Text Queries
Edit pageThe high-level full text queries are usually used for running full text queries on full text fields like the body of an email. They understand how the field being queried is process which means converting text, like the body of any email, into tokens or terms which are added to the inverted index for searching.
- Simple Query
- Phrase Query
- Wildcard Query
- Partial Query
- Fuzzy Query
- Near Query
- Love and Hate Query
- Default Operator
- Stop Words
The query string grammar
Section titled “The query string grammar”The text of a text query ("personality": "...", or the value after a field in q=)
is parsed by the queryparser library, with the words
analysed by the field’s own rules (language, stemming, stop words) so that query terms equal
index terms. The syntax, with the flag that enables each part:
| Syntax | Meaning | Applies |
|---|---|---|
a b | The default operator joins the words: OR. | always |
"a b", a-b, a:b, a/b | The words as a phrase. | always |
+a, -a | a is required, or excluded (Love and Hate). | always |
a* | Every word that starts with a (wildcard). | always |
b?a, ba*c* | Glob patterns inside a word. | with _wildcard |
ba**, the last word | Words that start with it, at most 50 (partial). | **, or with _partial |
word~, word~n | Words within edit distance n (2 by default) of the last word (fuzzy). | always, at the end of the text |
a AND b, a OR b, a NOT b, a XOR b, a AND NOT b | Boolean operators: OR binds loosest, then XOR, then AND and NOT. | only with _and or _or |
a NEAR b, a ADJ b, NEAR/n, ADJ/n | The words within a window of n + words - 1 positions (n is 10 by default; near). | only with _and or _or |
( ) | Groups. | always |
The words of a group that are stop words are dropped unless the group holds only stop
words (see Stop Words). A plain string never reads AND, OR,
NOT or XOR as operators: they are words. The _and and _or modifiers choose the
default operator and turn the boolean words on:
SEARCH /bank/?limit=0
{ "_query": { "personality": "adventurous creative" }}SEARCH /bank/?limit=0
{ "_query": { "personality": { "_and": "adventurous creative" } }}SEARCH /bank/?limit=0
{ "_query": { "personality": { "_and": "adventurous NOT creative" } }}SEARCH /bank/?limit=0
{ "_query": { "personality": "+adventurous -creative" }}SEARCH /bank/?limit=0
{ "_query": { "personality": "adventurous AND creative" }}A text that does not parse, such as an operator with a missing operand under _and, answers
400. Sources: the grammar table in the queryparser’s README; the flags the node sets,
src/query_dsl.cc:805-848; _and and _or set the boolean flag, src/query_dsl.cc:817-822.