Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save renshuki/afe5c9f4f6c97fdcf8d73f6952d477ee to your computer and use it in GitHub Desktop.
Save renshuki/afe5c9f4f6c97fdcf8d73f6952d477ee to your computer and use it in GitHub Desktop.
Elasticsearch term aggregation to regroup a field (key) and count the number of buckets using cardinality aggregation
GET rule_index/_search
{
  "size": 0,
  "aggs": {
    "rule_doc_count": {
      "terms" : { "field" : "key.keyword" }
    },
    "rule_count":{
      "cardinality": {
        "field": "key.keyword"
      }
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment