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
SetsubstringIndex: true on a text field when you create the collection. This request body for creating a collection enables it on three fields:
substringIndexis allowed ontextfields only, at the top level or inside an object. Sending it on any other field type, even asfalse, returns400. Omitting it,false, andnullall leave the index off.- It works alongside
analyzers.subjectandmetadata.note(which uses the default["standard"]) can be searched with query strings and filtered by substring.bodysets"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.
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 asubstring 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 offield 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 (statusesCandSofCaseFolding.txt), which maps one code point to one code point. Text is not normalized and full case folding is not applied, soßdoes not matchss,ẞmatchesß, and a precomposedédoes not matchefollowed 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
valuethat contains an unpaired surrogate is rejected.
Placement and scoring
Asubstring 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 abool:
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: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
400with 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
filterormust, and the query has no facets or hybrid fusion, LambdaDB checks candidates in result order and stops once it hassizeresults. The cost then depends on the non-matching candidates ranked before those results. Inknn.filterand in queries with facets, every candidate is checked, so a common value can exceed the budget.shouldandmust_notpositions can also check more candidates. - To stay within budget, combine the substring clause with selective filters, such as a
keywordcondition or apartitionFilter, and use longer values.
400 with the message shown:
See Limits for the other search limits.