Reference Entry
Term, Terms, Prefix, Exists, and Match Queries
Lexical Querying · querying · order 10
Use exact term lookups, field existence checks, prefix lookup, or analyzed text matching.
Relevant APIs
Term, Terms, Prefix, Exists, and Match Queries
TermQuery
TermQuery looks for an exact term in an indexed field. It does not analyze the input for you.
import { TermQuery } from "@tryformation/querylight-ts";
const query = new TermQuery({ field: "tags", text: "aggregation" });
TermsQuery
TermsQuery is the exact-match any-of variant for faceting and filters.
import { TermsQuery } from "@tryformation/querylight-ts";
const query = new TermsQuery({ field: "tags", terms: ["aggregation", "highlighting"] });
PrefixQuery
PrefixQuery looks for analyzed field terms through the field’s trie. It expands the prefix against real indexed vocabulary and then returns documents containing those matching terms.
It is useful for autocomplete-style retrieval when you want prefix lookup to be explicit instead of toggling prefixMatch on MatchQuery.
import { PrefixQuery } from "@tryformation/querylight-ts";
const query = new PrefixQuery({ field: "title", prefix: "agg" });
ExistsQuery
ExistsQuery filters documents that have at least one stored value for a field.
import { ExistsQuery } from "@tryformation/querylight-ts";
const query = new ExistsQuery({ field: "location" });
MatchQuery
MatchQuery analyzes the input text and supports both AND and OR logic. When prefixMatch is true, each analyzed query term can expand through the field trie before document scoring.
import { MatchQuery, OP } from "@tryformation/querylight-ts";
const bodyQuery = new MatchQuery({ field: "body", text: "vector search", operation: OP.AND, boost: 2.0 });
const prefixQuery = new MatchQuery({ field: "title", text: "agg", operation: OP.OR, prefixMatch: true });
MultiMatchQuery
MultiMatchQuery lets terms match across several fields instead of forcing one field to satisfy the whole query.
import { MultiMatchQuery } from "@tryformation/querylight-ts";
const query = new MultiMatchQuery({ fields: ["title", "body"], text: "vector search" });
When to prefer which
- Use
TermQueryfor exact facet values. - Use
TermsQueryfor exact any-of filters. - Use
PrefixQueryfor explicit autocomplete-style matching. - Use
ExistsQuerywhen optional metadata should become a filter. - Use
MatchQueryfor full text. - Use
MultiMatchQuerywhen query terms may be spread across several fields. - Turn on
prefixMatchwhen you want partial token lookup against known indexed terms instead of exact analyzed terms only.