Term query #
Returns documents that contain an exact term in a provided field.
You can use the term query to find documents based on a precise value such as a
price, a product ID, or a username. It is also the atom the rest of the
term-level family resolves to:
terms expands into a should of
term clauses, and prefix / wildcard / regexp / fuzzy all resolve to term
sets before execution.
Inside a
nestedquery: supported — the value is matched per array element. Ontextfields prefermatch;termtargets exact keyword / numeric / date values.
How it works #
The value is looked up verbatim in the field’s index — no analyzer and no normalizer runs on it, so what you send must equal exactly what was indexed, including whitespace and capitalization.
Which index serves the lookup depends on the field type:
keyword/text— a point lookup in the inverted index’s term dictionary, then the matching postings list. Ontextfields the stored terms are the analyzer’s output (thestandardanalyzer lowercases), so"value": "Error"finds nothing when every token was indexed aserror. Prefermatchfor analyzed text — it runs the analyzer for you.- numeric /
date— the per-field BKD range index (or the column store’s value-sorted region on merged segments without a BKD index): the dispatcher routes numerictermqueries there, because a text-dictionary lookup of a number would always miss. The bound is matched as a single point. boolean— the column store’s Bool column. String values normalize first ("true","1","yes","ok"count as true;"false","0","no"as false).
Scoring. On keyword / text the hit is scored with BM25 like any
postings match, so rare values rank higher. On numeric, date and boolean
fields the hit gets a constant score — the boost (1.0 by default) —
which makes those forms natural bool filter clauses: they constrain
the result set without distorting relevance.
Examples #
The following search returns the log lines whose level is exactly
error — 25 of the 150 documents in the logs dataset.
GET /_search
{
"query": {
"term": {
"field": "org.id",
"value": "infini"
}
}
}
Use cases #
- Enums and statuses.
level,status,tierare keyword fields with a closed vocabulary —termonsales.status = "pending"returns 40 of the 120 sales,termoncustomers.tier = "gold"returns 4 of 20. - Exact numeric points. A
termonsales.price = 45matches the 20 sales at that price through the BKD index — the one-value special case of arangequery. - ID lookups. Slugs, SKUs, hostnames (
host = "web-01"→ 50 of 150 log lines) — values you want whole, never tokenized or scored by frequency. - Filter clauses. Inside
bool.filter, aterm’s BM25 input is ignored anyway, so exact-value filtering costs nothing in relevance quality. - Tag membership. A
termon thearticles.tagskeyword array ("search") matches the 2 articles carrying that tag — array fields index each value as a term.
Parameters for term
#
field
(Required, string) Field you wish to search.value
(Required, string, number or boolean) Term you wish to find in the providedfield. To return a document, the term must exactly match the field value, including whitespace and capitalization.case_insensitive
(Optional, boolean) Allows ASCII case insensitive matching of the value with the indexed field values when set totrue. Default isfalse.boost
(Optional, float, default:1.0) Decrease or increase the relevance scores of the query.
Related #
terms— any-of-a-set over exact values; expands to aboolshouldoftermclauses.range— the interval generalization for numeric and date fields, served by the same BKD index.fuzzy— near-miss matching when the exact term is unknown or misspelled.keys— matching by document identity instead of by field value.match— the analyzed alternative fortextfields.termsaggregation — the bucket view of the same keyword vocabulary atermquery filters on.