Terms Aggregation

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

Whenever is possible, prefer Values Aggregation to this type as it’s more efficient.


The following snippet captures the structure of range aggregations:

"<aggregation_name>": {
  "_terms": {
    "_field": "<field_name>"

Also supports all other functionality as explained in Bucket Aggregations.


The <field_name> in the _field parameter defines the field on which the aggregation will act upon.

Assuming the data consists of documents representing bank accounts, as shown in the sample dataset of Data Exploration section:

SEARCH /bank/
  "_query": "*",
  "_limit": 0,
  "_check_at_least": 1000,
  "_aggregations": {
    "most_used_terms": {
      "_terms": {
        "_field": "personality"


  "aggregations": {
    "_doc_count": 1000,
    "most_used_terms": [
  }, ...


By default, the returned buckets are sorted by their _doc_count descending, though the order behaviour can be controlled using the _sort setting. Supports the same order functionality as explained in Bucket Ordering.