Skip to main content
LambdaDB supports a simple string query that uses the Lucene Query Syntax to search documents. This gives queryString access to expressive lexical search features such as terms, phrases, wildcards, boolean operators, range operators, proximity search, regular expressions, fuzzy term matching, term boosting, minimum-should-match constraints, interval functions, and special character escaping.

Supported syntax highlights

FeatureExampleUse it to
Term searchhelloMatch documents containing a term.
Phrase search"hello world"Match an exact phrase.
Field searchtitle:LambdaDBTarget a specific field.
Boolean logic and groupingtitle:database AND (serverless OR managed)Combine required, optional, and excluded clauses.
Wildcardsvector*Match terms by prefix or pattern.
Proximity search"serverless database"~4Match words that occur near each other.
Regular expression/vec(tor|tors)/Match terms using a regular expression.
Fuzzy term matchinglambdadb~2Match terms within an edit distance.
Range querycreated_at:[2024-01-01T00:00:00Z TO *]Match numeric, datetime, or keyword ranges.
Term boostingdatabase^2 OR storage^0.5Increase or decrease the relevance weight of clauses.
Minimum should match(semantic vector keyword)@2Require at least N optional clauses to match.
Interval functionfn:ordered(serverless vector database)Express ordered or positional relationships between terms.

Parameters

ParameterDescriptionTypeRequiredDefault
queryQuery stringstring
defaultFieldDefault field name to apply querystring
skipSyntaxSkip syntax check for special charactersbooleanfalse
A query to a collection with object field type requires special handling.

Examples

Basic query

{
  "queryString": {
    "query": "hello world",
    "defaultField": "text"
  }
}
When multiple terms are separated by spaces, each term is treated as an optional clause on the defaultField. The above example is equivalent to:
{
  "queryString": {
    "query": "text:hello OR text:world"
  }
}
You can also query multiple fields by specifying field names in the query string. Terms are separated by spaces, and specific fields are targeted using the field:value syntax:
{
  "queryString": {
    "query": "hello world keyword:python",
    "defaultField": "text"
  }
}

Exact keyword match

Use a keyword field when you want to match a literal value instead of analyzed text.
{
  "queryString": {
    "query": "python",
    "defaultField": "keyword"
  }
}
If the keyword contains spaces or query syntax characters, wrap the value in double quotes ("):
{
  "queryString": {
    "query": "\"hello world\"",
    "defaultField": "keyword"
  }
}
For raw literal values that include special characters, you can also use the skipSyntax option:
{
  "queryString": {
    "query": "https://sample_url.com",
    "defaultField": "keyword",
    "skipSyntax": true
  }
}
Alternatively, quote the literal value:
{
  "queryString": {
    "query": "\"https://sample_url.com\"",
    "defaultField": "keyword"
  }
}
On analyzed text fields, wrap terms in double quotes (") to search for an exact phrase.
{
  "queryString": {
    "query": "\"serverless database\"",
    "defaultField": "content"
  }
}
Use proximity search to match phrase terms that appear near each other, even when they are not adjacent. The number after ~ controls the maximum distance between phrase terms.
{
  "queryString": {
    "query": "\"serverless database\"~4",
    "defaultField": "content"
  }
}

Regular expression query

Wrap a regular expression in forward slashes (/) to match terms by pattern.
{
  "queryString": {
    "query": "/vec(tor|tors)/",
    "defaultField": "content"
  }
}

Fuzzy term matching

Use ~ after a term to match terms within an edit distance. This is useful for typos, spelling variants, and noisy text.
{
  "queryString": {
    "query": "lambdadb~2",
    "defaultField": "content"
  }
}

Term boosting

Use ^ to increase or decrease the relevance weight of a term, phrase, range expression, or grouped clause.
{
  "queryString": {
    "query": "database^2 OR storage^0.5",
    "defaultField": "content"
  }
}
You can also boost a grouped sub-query:
{
  "queryString": {
    "query": "title:(serverless OR managed)^2.5 OR content:database"
  }
}

Minimum should match

Use the minimum-should-match operator (@) on a disjunction group to require at least the specified number of optional clauses to match.
{
  "queryString": {
    "query": "(semantic vector keyword)@2",
    "defaultField": "content"
  }
}

Interval function

Use interval functions with the fn: prefix to express ordered or positional relationships between terms.
{
  "queryString": {
    "query": "fn:ordered(serverless vector database)",
    "defaultField": "content"
  }
}
You can target a field and combine interval functions:
{
  "queryString": {
    "query": "title:fn:maxwidth(5 fn:atLeast(2 serverless vector database))"
  }
}

Range query

Range queries allow you to search for values within a specific range using range query syntax.

Supported field types

Range queries work with the following field types:
  • long
  • double
  • datetime
  • keyword

Syntax

  • Inclusive range: [min TO max] includes both lower and upper bounds.
  • Exclusive range: {min TO max} excludes both lower and upper bounds.
{
  "queryString": {
    "query": "[123 TO 456]",
    "defaultField": "long"
  }
}
{
  "queryString": {
    "query": "{2024-03-10T09:15:45Z TO 2024-03-10T09:15:46Z}",
    "defaultField": "datetime"
  }
}