Skip to main content
A substring clause matches documents whose text field contains a given string exactly. Use it for literal lookups that text analysis does not handle, such as order numbers, code identifiers, log fragments, or part of a word. It is a filter: it does not affect scores, and it can be combined with any other query. Query string search splits text into terms with the field’s analyzers and ranks matches. A substring filter compares the stored text instead: Order #A-1024 matches only text that contains those characters in that order, and efund matches refund. The examples on this page are REST request bodies.

Enable the substring index

Set substringIndex: true on a text field when you create the collection. This request body for creating a collection enables it on three fields:
  • substringIndex is allowed on text fields only, at the top level or inside an object. Sending it on any other field type, even as false, returns 400. Omitting it, false, and null all leave the index off.
  • It works alongside analyzers. subject and metadata.note (which uses the default ["standard"]) can be searched with query strings and filtered by substring. body sets "analyzers": [], so it is indexed for substring filters only and is not searchable with query strings.
  • The substring index adds indexing work and index size for the field.
You can enable the index only when the collection is created. It cannot be added to, changed on, or removed from an existing field, and a schema update that adds a new field with substringIndex: true returns 400. To filter an existing field by substring, create a new collection with the option and import the documents again.

Filter with a substring clause

Place a substring clause wherever a query clause is accepted. This query request body returns open tickets whose body contains Order #A-1024:

What matches

A document matches when its string value of field contains value as a contiguous sequence of Unicode code points. The value is not analyzed: there is no tokenization or stemming, and *, ?, and other characters have no special meaning.
  • By default the comparison is case-sensitive.
  • With ignoreCase: true, both sides are compared after Unicode 16.0.0 simple case folding (statuses C and S of CaseFolding.txt), which maps one code point to one code point. Text is not normalized and full case folding is not applied, so ß does not match ss, ẞ matches ß, and a precomposed é does not match e followed by a combining accent. If you compare results with a client-side search, a client that uses a later Unicode version can fold characters assigned after Unicode 16.0.0 differently.
  • A document without the field, or with null, does not match.
  • An unpaired surrogate in a document’s text is matched as U+FFFD. A value that contains an unpaired surrogate is rejected.

Placement and scoring

A substring clause is accepted in a bool at any depth and with any occur, in knn.filter, inside the subqueries of a hybrid query, in queries with facets, in list filters, and in delete filters. The clause never contributes to the score, and a boost on it has no effect. Under filter or must it restricts the results, and under must_not it excludes matching documents. A query whose only clause is substring returns its matches with a score of 0. Following the boolean query rules, a should substring clause beside a must or filter clause changes neither the results nor the scores. Substring filters read the same documents as other filters: a consistent read of a branch includes its pending writes, and a read of a tag includes the pending writes the tag captured.

List documents with a substring filter

An extended list request accepts a substring filter on its own or inside a bool:
With a substring filter, a page can hold fewer than size documents, or none, while nextPageToken is present. The page ends early when checking candidates reaches the verification budget, and the token continues from where the check stopped. Keep requesting pages until nextPageToken is absent; a short or empty page is not the end of the list.

Delete documents by substring

A delete by query accepts a substring filter and deletes every matching document:
Until the delete is indexed, reads that include pending writes check the documents it can remove, and that work counts toward the read’s verification budget. A broad pending substring delete can make such reads return the verification error until indexing catches up.

Limits and errors

LambdaDB uses the substring index to find candidate documents and then checks each candidate’s stored text. A value of one or two code points expands to every indexed term that starts with it. These budgets bound that work: The candidate and stored-data budgets together make up the verification budget. The budgets apply to each search LambdaDB runs to serve a request, so a request that reads both published data and pending writes can check more in total.
  • A query that exceeds a budget returns 400 with no partial results.
  • A list request that reaches the verification budget ends the page early instead. Exceeding the index-term budget, or exceeding the verification budget while checking a pending substring delete, still returns 400.
  • When every substring clause of a query is reached only through filter or must, and the query has no facets or hybrid fusion, LambdaDB checks candidates in result order and stops once it has size results. The cost then depends on the non-matching candidates ranked before those results. In knn.filter and in queries with facets, every candidate is checked, so a common value can exceed the budget. should and must_not positions can also check more candidates.
  • To stay within budget, combine the substring clause with selective filters, such as a keyword condition or a partitionFilter, and use longer values.
Every error below returns HTTP 400 with the message shown: See Limits for the other search limits.