Loading...

Aggregations in the Elasticsearch Query DSL

:heavy_exclamation_mark: This post is older than a year. Consider some information might not be accurate anymore. :heavy_exclamation_mark:

A small example how to count documents in Elasticsearch using the Query DSL Aggregations.

GET ep2-itu-2017.02.06/ep2/_search
{
  "size": 0,
  "aggs": {
    "applications": {
      "terms": {
        "field": "application"
      }
    }
  }
}

This is the result. Results

{
  "took": 1565,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "failed": 0
  },
  "hits": {
    "total": 46331398,
    "max_score": 0,
    "hits": []
  },
  "aggregations": {
    "applications": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 0,
      "buckets": [
        {
          "key": "ep2-batch",
          "doc_count": 46170714
        },
        {
          "key": "ep2-gateway",
          "doc_count": 145087
        },
        {
          "key": "ep2-proxy",
          "doc_count": 14956
        },
        {
          "key": "ep2-scs",
          "doc_count": 46
        }
      ]
    }
  }
}
Please remember the terms for blog comments.