Include/Exclude for cardinality aggregation

I have a terms aggregation with an IncludeExclude filter:

{
  "size": 0,
  "query": {
    ...
  },
 "aggregations": {
    "facets": {
      "terms": {
        "field": "type_id",
        "size": 20,
        "order": [
          {
            "_count": "desc"
          },
          {
            "_key": "asc"
          }
        ],
        "include": "PARENT$.*",
        "exclude": ".+__\\*"
      }
    }
}

This will return me the top 20 facets for field type_id. I also want to know the total number of unique terms for this facet, so I want to add another aggregate:

 "total": {
      "cardinality": {
        "field": "type_id"
      }
    }

but I can't filter this total by include/exclude, so the count doesn't match with the terms aggregate above. Is there an efficient way to achieve this?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.