Term level queriesedit

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.
missing query
Find documents where the field specified does is missing or contains only null values.
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 Queryedit

See Term Query

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

field

text

Terms Queryedit

See Terms Query

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

field

values

Range Queryedit

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 Queryedit

See Exists Query.

QueryBuilder qb = existsQuery("name");       

field

Missing Queryedit

Warning

Deprecated in 2.2.0.

Use exists query inside a must_not clause instead

See Missing Query

QueryBuilder qb = missingQuery("user");         
    .existence(true)                            
    .nullValue(true);                           

field

find missing field that doesn’t exist

find missing field with an explicit null value

Prefix Queryedit

See Prefix Query

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

field

prefix

Wildcard Queryedit

See Wildcard Query

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

Regexp Queryedit

See Regexp Query

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

field

regexp

Fuzzy Queryedit

See Fuzzy Query

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

field

text

Type Queryedit

See Type Query

QueryBuilder qb = typeQuery("my_type"); 

type

Ids Queryedit

See Ids Query

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

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

type is optional