Visualization with unique count of fields combination

Hi everyone,

I'm trying to create a visualization of a cardinality aggregation on two fields but haven't found a proper way to do it yet. I'm fairly new to the Elastic stack so bear with me :slight_smile:

I have this query which provides me with what I need:

GET myindex-2019.07/_search
  "size": 0,
  "aggs": {
    "my_count": {
      "cardinality": {
        "script": {
          "source": "[doc['field1'], doc['field2']]"

This gives me the following result:

  "took" : 1236,
  "timed_out" : false,
  "_shards" : {
  "total" : 3,
  "successful" : 3,
  "skipped" : 0,
  "failed" : 0
  "hits" : {
  "total" : 3081982,
  "max_score" : 0.0,
  "hits" : [ ]
  "aggregations" : {
  "my_count" : {
  "value" : 158

Next I need to create a visualization for the "my_count" value:

The only idea I've had so far is a metric-visualization with JSON Input, but for obvious reasons this doesn't work. It makes no sense to set the field value to "field1 when what I'm after is a combination of two fields.

Looks like this:

Maybe I'm on the proverbial wild goose chase here? :slight_smile:

Any help is appreciated.


1 Like

What does the first script calculate? The number of unique documents combined in field1 and field2?

Yes, at least thats what I hope it does. The value seems to match the expected result at least.

Found it in this post: Cardinality aggregation on several fields

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