Querylight TS Demo

Term, Terms, Prefix, Exists, and Match Queries

Use exact term lookups, field existence checks, prefix lookup, or analyzed text matching.

Back to docs search

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.

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 TermQuery for exact facet values.
  • Use TermsQuery for exact any-of filters.
  • Use PrefixQuery for explicit autocomplete-style matching.
  • Use ExistsQuery when optional metadata should become a filter.
  • Use MatchQuery for full text.
  • Use MultiMatchQuery when query terms may be spread across several fields.
  • Turn on prefixMatch when you want partial token lookup against known indexed terms instead of exact analyzed terms only.

Learn more