Terms aggregation

Terms aggregation #

A multi-bucket value source based aggregation where buckets are dynamically built - one per unique value.

Examples #

POST /_search
{
  "aggs": {
    "genres": {
      "terms": {
        "field": "genre"
      }
    }
  }
}

Response:

{
  ...
  "aggregations": {
    "genres": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 0,
      "buckets": [
        {
          "key": "electronic",
          "doc_count": 6
        },
        {
          "key": "rock",
          "doc_count": 3
        },
        {
          "key": "jazz",
          "doc_count": 2
        }
      ]
    }
  }
}

Parameters for terms #

  • field
    (Required, string) Field you wish to aggregate.
  • size
    (Optional, integer) Maximum number of buckets to return. Defaults to 10.
  • min_doc_count
    (Optional, integer) Drop buckets with fewer matching documents. Defaults to 1; 0 keeps empty buckets — only meaningful together with an explicit include list.
  • missing
    (Optional, value) Value substituted for documents without the field (any scalar; those documents land in one bucket keyed by it).
  • include
    (Optional) Restricts bucket keys: an exact-value array, a wildcard string (prefix* / *suffix), or { "partition": <p>, "num_partitions": <n> }.
  • exclude
    (Optional) Excludes bucket keys: an exact-value array or a wildcard string (negated include).
  • aggs
    (Optional, object) Nested sub-aggregations, computed per bucket.
Calendar September 26, 2026
Edit Edit this page