# Cardinality Pipeline

**URL:** https://discuss.elastic.co/t/cardinality-pipeline/169098
**Category:** Elasticsearch
**Created:** [February 19, 2019, 7:17pm UTC](https://discuss.elastic.co/t/cardinality-pipeline/169098 "2019-02-19T19:17:20Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Ricky\_Barillas](https://avatars.discourse-cdn.com/v4/letter/r/7cd45c/32.png) [@Ricky\_Barillas](https://discuss.elastic.co/u/Ricky_Barillas)
#### Post date: [February 19, 2019, 7:17pm UTC](https://discuss.elastic.co/t/cardinality-pipeline/169098/1 "2019-02-19T19:17:21Z")

</div>

I have what seems to be like a pipelined bucket aggregation with cardinality. I have two types of documents: Accounts and Reports.

An account loosely looks like this

```
type AccountDoc struct {
    AccountAlias string `json:"account_alias"`
    AccountEnrolled bool `json:"account_enrolled"`
}

```

And a report loosely looks like this

```
type ReportingDoc struct {
    ID string `json:"id,omitempty"`
    Enrolled bool `json:"enrolled"`
    AllAccounts []string `json:"all_accounts,omitempty"`
}

```

The goal is "for every unique AccountAlias give me the number of Reports that include the AccountAlias in the array AllAccounts"

It seems like I would need some form of a nested query/aggregation which to me sounds like a pipeline but im also bucketing by unique AccountAlias

I am not married to the document schema for the AccountDoc, but I am married to the goal.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [March 19, 2019, 7:17pm UTC](https://discuss.elastic.co/t/cardinality-pipeline/169098/2 "2019-03-19T19:17:21Z")

</div>

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