How to get a count from an aggregation?

Sorry if this sounds like a duplicate. I've been reading all the various count/aggregation threads and I haven't really been able to figure this one out yet.

POST /profile/_search
{
  "size": 0,
  "aggregations": {
    "az_profile": {
      "nested": {
        "path": "az"
      },
      "aggregations": {
        "duplicateCount": {
          "terms": {
            "field": "az.account",
            "min_doc_count": 2,
            "size": 1000
          }
        }
      }
    }
  }
}

This returns me the counts each az.account with a minimum count of 2.

Now how would I add an aggregation to get a count for how many az.accounts that aggregation returned?

I basically need an integer count on my first aggregated query

hey, so I figured it out!

POST /profile/_search
{
  "size": 0,
  "aggregations": {
    "az_profile": {
      "nested": {
        "path": "az"
      },
      "aggregations": {
        "duplicateCount": {
          "terms": {
            "field": "az.visitor",
            "min_doc_count": 2,
            "size": 1000
          }
        },
        "distinct_count":{
          "cardinality":{
            "field": "az.visitor"
          }
        }
      }
    }
  }
}

Is there anyway to only get back the cardinality part of my aggregation?

that was actually pretty easy, I just had to remove the middle aggregation section of my previous aggregate.

Thanks for Being My Rubber Duck, discuss.elastic :stuck_out_tongue:

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