Terms

Terms aggregation

/ Terms, / Aggregation

Terms aggregation #

A multi-bucket value source based aggregation where buckets are dynamically built - one per unique value. It answers “group by this field, count (and aggregate) per value” without knowing the values in advance, which a fixed-bucket aggregation like histogram or range cannot do.

How it works #

Every matching document is placed in the bucket keyed by its value of field. Multi-valued fields bucket per element: a document whose tags holds ["search", "architecture"] is counted once in the search bucket and once in the architecture bucket. Documents without the field are skipped — unless missing is set, in which case they land together in one bucket keyed by that value.

...

Terms query

/ Terms, / Query

Terms query #

Returns documents that contain one or more exact terms in a provided field. Equivalent to a boolean should of individual term queries — a document matches if it contains any of the values.

Inside a nested query: not supported yet — the clause is rejected with an HTTP 400 naming the offending clause. Expand into a bool should of term clauses instead.

How it works #

The planner expands the query before execution: each value becomes a term clause inside a BooleanQuery with minimum_should_match: 1, and a single-value terms collapses straight into one bare term query. Everything said on the term page about verbatim lookup, index routing (dictionary for keyword/text, BKD for numeric/date, Bool column for boolean) and BM25 scoring therefore applies per value here, with the per-value scores OR-ed together.

...