Skip to content

Text Queries

Edit page

The 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.

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:

SyntaxMeaningApplies
a bThe default operator joins the words: OR.always
"a b", a-b, a:b, a/bThe words as a phrase.always
+a, -aa 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 wordWords that start with it, at most 50 (partial).**, or with _partial
word~, word~nWords 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 bBoolean operators: OR binds loosest, then XOR, then AND and NOT.only with _and or _or
a NEAR b, a ADJ b, NEAR/n, ADJ/nThe 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.