You could use a script in the cardinality aggregation to add the values for each of the fields to an array and return the array. See the following for a simple example of this:
PUT test/doc/1
{
"field1": "value1",
"field2": "value2"
}
PUT test/doc/2
{
"field1": "value2",
"field2": "value3"
}
PUT test/doc/3
{
"field1": "value1",
"field2": "value3"
}
PUT test/doc/4
{
"field1": "value3",
"field2": "value4"
}
GET test/_search
{
"size": 0,
"aggs": {
"cardinality": {
"cardinality": {
"script": {
"inline": "[ doc['field1'].value, doc['field2'].value ]"
}
}
}
}
}