Term level queries

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 Query

See Term Query

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

field

text

Terms Query

See Terms Query

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

field

values

Range Query

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

See Exists Query.

QueryBuilder qb = existsQuery("name");       

field

Missing Query

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 Query

See Prefix Query

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

field

prefix

Wildcard Query

See Wildcard Query

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

Regexp Query

See Regexp Query

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

field

regexp

Fuzzy Query

See Fuzzy Query

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

field

text

Type Query

See Type Query

QueryBuilder qb = typeQuery("my_type"); 

type

Ids Query

See Ids Query

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

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

type is optional