Term level queries

edit

Term level queries

edit

While the full text queries will analyze the query string before executing, the term-level queries operate on the exact terms that are stored in the inverted index.

These queries are usually used for structured data like numbers, dates, and enums, rather than full text fields. Alternatively, they allow you to craft low-level queries, foregoing the analysis process.

The queries in this group are:

term query
Find documents which contain the exact term specified in the field specified.
terms query
Find documents which contain any of the exact terms specified in the field specified.
range query
Find documents where the field specified contains values (dates, numbers, or strings) in the range specified.
exists query
Find documents where the field specified contains any non-null value.
prefix query
Find documents where the field specified contains terms which being with the exact prefix specified.
wildcard query
Find documents where the field specified contains terms which match the pattern specified, where the pattern supports single character wildcards (?) and multi-character wildcards (*)
regexp query
Find documents where the field specified contains terms which match the regular expression specified.
fuzzy query
Find documents where the field specified contains terms which are fuzzily similar to the specified term. Fuzziness is measured as a Levenshtein edit distance of 1 or 2.
type query
Find documents of the specified type.
ids query
Find documents with the specified type and IDs.

Term Query

edit

See Term Query

QueryBuilder qb = termQuery(
    "name",    
    "kimchy"   
);

field

text

Terms Query

edit

See Terms Query

QueryBuilder qb = termsQuery("tags",    
    "blue", "pill");                    

field

values

Range Query

edit

See Range Query

QueryBuilder qb = rangeQuery("price")   
    .from(5)                            
    .to(10)                             
    .includeLower(true)                 
    .includeUpper(false);               

field

from

to

include lower value means that from is gt when false or gte when true

include upper value means that to is lt when false or lte when true

// A simplified form using gte, gt, lt or lte
QueryBuilder qb = rangeQuery("age")   
    .gte("10")                        
    .lt("20");                        

field

set from to 10 and includeLower to true

set to to 20 and includeUpper to false

Exists Query

edit

See Exists Query.

QueryBuilder qb = existsQuery("name");       

field

Prefix Query

edit

See Prefix Query

QueryBuilder qb = prefixQuery(
    "brand",    
    "heine"     
);

field

prefix

Wildcard Query

edit

See Wildcard Query

QueryBuilder qb = wildcardQuery("user", "k?mc*");

Regexp Query

edit

See Regexp Query

QueryBuilder qb = regexpQuery(
    "name.first",        
    "s.*y");             

field

regexp

Fuzzy Query

edit

Deprecated in 5.0.0.

Will be removed without a replacement for string fields. Note that the fuzziness parameter is still supported for match queries and in suggesters. Use range queries for date and numeric fields instead.

See Fuzzy Query

QueryBuilder qb = fuzzyQuery(
    "name",     
    "kimzhy"    
);

field

text

Type Query

edit

See Type Query

QueryBuilder qb = typeQuery("my_type"); 

type

Ids Query

edit

See Ids Query

QueryBuilder qb = idsQuery("my_type", "type2")
    .addIds("1", "4", "100");

QueryBuilder qb = idsQuery() 
    .addIds("1", "4", "100");

type is optional