# How to get the count of a pair of field values?

**URL:** <https://discuss.elastic.co/t/how-to-get-the-count-of-a-pair-of-field-values/100562>\
**Category:** Elasticsearch\
**Created:** [September 14, 2017, 2:37pm UTC](https://discuss.elastic.co/t/how-to-get-the-count-of-a-pair-of-field-values/100562 "2017-09-14T14:37:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![WoJ](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/woj/32/4518_2.png) [@WoJ](https://discuss.elastic.co/u/WoJ)\
**Post date:** [September 14, 2017, 2:37pm UTC](https://discuss.elastic.co/t/how-to-get-the-count-of-a-pair-of-field-values/100562/1 "2017-09-14T14:37:25Z")

</div>

Hello

I need to build a heatmap from the data I have in elasticsearch. The heatmap is the count of cases where two specific fields have the same value. For the data

```
{'name': 'john', 'age': '10', 'car': 'peugeot'}
{'name': 'john', 'age': '10', 'car': 'audi'}
{'name': 'john', 'age': '12', 'car': 'fiat'}
{'name': 'mary', 'age': '3', 'car': 'mercedes'}

```

I would like to get the number of unique pairs for the values of `name` and `age`. That would be

```
john, 10, 2
john, 12, 1
mary, 3, 1

```

I could get all the events and make the count myself but I was hoping that there would be some magical aggregation which could provide that.

It would not be a problem to have it in a nested form, such as

```
{
  'john':
    {
      '10': 2,
      '12': 1
    },
  'mary':
    {
      '3': 1
    },
}

```

or whatever is practical.

Thanks!

---

<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:** [October 12, 2017, 2:37pm UTC](https://discuss.elastic.co/t/how-to-get-the-count-of-a-pair-of-field-values/100562/2 "2017-10-12T14:37:58Z")

</div>

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