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

termQuery(
        "name",                                              
        "kimchy");                                           

field

text

Terms Query

edit

See Terms Query

termsQuery("tags",                                           
        "blue", "pill");                                     

field

values

Range Query

edit

See Range Query

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

existsQuery("name");                                         

field

Prefix Query

edit

See Prefix Query

prefixQuery(
        "brand",                                             
        "heine");                                            

field

prefix

Wildcard Query

edit

See Wildcard Query

wildcardQuery(
        "user",                                              
        "k?mch*");                                           

field

wildcard expression

Regexp Query

edit

See Regexp Query

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

field

regexp

Fuzzy Query

edit

See Fuzzy Query

fuzzyQuery(
        "name",                                              
        "kimchy");                                           

field

text

Type Query

edit

Deprecated in 7.0.0.

Types are being removed, prefer filtering on a field instead. For more information, see Removal of mapping types.

See Type Query

typeQuery("my_type");                                        

type

Ids Query

edit

See Ids Query

idsQuery()                                                   
        .addIds("1", "4", "100");