# Aggregations: How to get number of combinations

**URL:** <https://discuss.elastic.co/t/aggregations-how-to-get-number-of-combinations/333560>\
**Category:** Elasticsearch\
**Created:** [May 16, 2023, 11:24am UTC](https://discuss.elastic.co/t/aggregations-how-to-get-number-of-combinations/333560 "2023-05-16T11:24:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![es\_make](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/es_make/32/121078_2.png) [@es\_make](https://discuss.elastic.co/u/es_make)\
**Post date:** [May 16, 2023, 11:24am UTC](https://discuss.elastic.co/t/aggregations-how-to-get-number-of-combinations/333560/1 "2023-05-16T11:24:11Z")

</div>

Hello,

Let's say we have a simple ES index having two fields: "name" (string) and "expired" (boolean) in one nested object "products" (array). Each product name can be mentioned only once in each document.

Here's the example data:

```auto
{doc_id: 1, products: [{name: "apple", expired:true}, {name: "banana", expired:true}, {name: "orange", expired:true}]}
{doc_id: 2, products: [{name: "apple", expired:false}, {name: "banana", expired:true}, {name: "orange", expired:true}]}
{doc_id: 3, products: [{name: "apple", expired:false}, {name: "banana", expired:true}, {name: "orange", expired:true}]}
{doc_id: 4, products: [{name: "apple", expired:false}, {name: "banana", expired:false}, {name: "orange", expired:false}]}

```

1. How to get doc\_count for all product combinations?  
Expected result:

```auto
{products: [{name: "apple", expired:true}, {name: "banana", expired:true}, {name: "orange", expired:true}], doc_count: 1}
{products: [{name: "apple", expired:false}, {name: "banana", expired:true}, {name: "orange", expired:true}], doc_count: 2}
{products: [{name: "apple", expired:false}, {name: "banana", expired:false}, {name: "orange", expired:false}], doc_count: 1}

```

1. How to get doc\_count for selected product combinations?  
Expected result for filter "banana" AND "orange":

```auto
{products: [{name: "banana", expired:true}, {name: "orange", expired:true}], doc_count: 3}
{products: [{name: "banana", expired:false}, {name: "orange", expired:false}], doc_count: 1}

```

---

<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:** [June 13, 2023, 11:24am UTC](https://discuss.elastic.co/t/aggregations-how-to-get-number-of-combinations/333560/2 "2023-06-13T11:24:34Z")

</div>

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