# Visualization with unique count of fields combination

**URL:** <https://discuss.elastic.co/t/visualization-with-unique-count-of-fields-combination/191107>\
**Category:** Kibana\
**Created:** [July 17, 2019, 11:07pm UTC](https://discuss.elastic.co/t/visualization-with-unique-count-of-fields-combination/191107 "2019-07-17T23:07:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![henrix](https://avatars.discourse-cdn.com/v4/letter/h/dec6dc/32.png) [@henrix](https://discuss.elastic.co/u/henrix)\
**Post date:** [July 17, 2019, 11:07pm UTC](https://discuss.elastic.co/t/visualization-with-unique-count-of-fields-combination/191107/1 "2019-07-17T23:07:34Z")

</div>

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 🙂

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:

 ![Kibana%20visualization](https://us1.discourse-cdn.com/elastic/original/3X/8/9/89a42d3ce5a5ee9792c91a1443b537f67379dc2c.jpeg)

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

Any help is appreciated.

-J

---

<div class="post-metadata">

**Author:** ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)\
**Post date:** [July 18, 2019, 4:59pm UTC](https://discuss.elastic.co/t/visualization-with-unique-count-of-fields-combination/191107/2 "2019-07-18T16:59:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![henrix](https://avatars.discourse-cdn.com/v4/letter/h/dec6dc/32.png) [@henrix](https://discuss.elastic.co/u/henrix)\
**Post date:** [July 18, 2019, 5:20pm UTC](https://discuss.elastic.co/t/visualization-with-unique-count-of-fields-combination/191107/3 "2019-07-18T17:20:15Z")

</div>

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](https://discuss.elastic.co/t/cardinality-aggregation-on-several-fields/34519)

---

<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:** [August 15, 2019, 5:20pm UTC](https://discuss.elastic.co/t/visualization-with-unique-count-of-fields-combination/191107/4 "2019-08-15T17:20:17Z")

</div>

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