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

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!

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